Problems placing view on top of SlidingPaneLayout - android

I want to place a view via include on top of a SlidingPaneLayout. In the layout preview of AndroĆ­d Studio it is displayed correctly but on my device the view won't show - why?
Here is the complete layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="#layout/online_state"
android:layout_height="5dp"
android:layout_width="wrap_content"/>
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/content_view_spl"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/color_background_primary"
android:orientation="vertical" >
<de.timroes.android.listview.EnhancedListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="?attr/color_background_primary"
android:divider="#color/black"
android:dividerHeight="1dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/selected_item"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>

Ok, got it...
I have to place the SlidingPaneLayout below the view...
Stupid question... sorry ;)

Related

How to fix ListView inside ScrollView?

I need to put a ListView inside ScrollBar. I know there is other question about this theme but the answers are very complex and bad.
The ListView doesn't show all its elements, only the first one.
The main structure of my relevant code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....MORE ELEMENTS....
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Put your ListView in a separate LinearLayout parent or you can add it in a separate .xml file according to your choice and add
android:fillViewport="true"
in your scrollview, like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!....MORE ELEMENTS....>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>

Android Scrollview doesn't show up all the content

I am trying to display listviews and scroll down them in the page. However, scroll doesn't show up all the content, scrolls only like 30dp and there are a lot more listviews to display. There are many questions regarding this but they don't work on my code. I would appreciate if you could tell me what i am missing in the code below. Thank you
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="183dp"
tools:context=".MainActivity"
android:weightSum="1"
android:id="#+id/rel">
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="171dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:layout_alignParentBottom="true">
</android.support.v4.view.ViewPager>
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="479dp"
tools:context=".MainActivity"
android:weightSum="1"
android:id="#+id/rel2"
android:gravity="left|right">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignWithParentIfMissing="false" />
</RelativeLayout>
</LinearLayout>
You should never put a ListView inside a ScrollView. This can, and probably will, cause the list view to have bad beahvior like not scrolling.

"layout_alignParentBottom" does not work in the Layout

I was adding a Bottom Bar below the ViewPager (on the bottom of the screen) by using include but it does not work. I have tried all the methods by adding LinearLayout/ RelativeLayout to wrap the include tag, even ViewPager; or adding code like layout_alignParentBottom=true, layout_gravity=bottom.
Is there any method to put it at the bottom, or any problem in my code?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:orientation="vertical" >
<include layout="#layout/Bottom_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"/>
<android.support.v4.view.ViewPager
android:id="#+id/id_viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</LinearLayout>
just try like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<include layout="#layout/Bottom_bar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"/>
<android.support.v4.view.ViewPager
android:id="#+id/id_viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
</RelativeLayout>
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/id_viewpager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
</android.support.v4.view.ViewPager>
<include layout="#layout/Bottom_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
LinearLayout draws every child by the order it is declared, so if Bottom_bar is declared before id_viewpager, it will draw above ViewPager. If you switch the order, you'll get what you want.

Android layout_above does not work on API 21

I have a RelativeLayout that contains 3 children (LinearLayout) :
one at the top.
one at the bottom.
and one between the 2 last views.
The code i use for it is :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:layout_alignParentTop="true"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/game_main_actionbar"
android:layout_above="#+id/game_main_chat_container">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</RelativeLayout>
Since the api 21 the attribut 'android:layout_above' is not working : the second LinearLayout take all the space below the first one, and the third LinearLayout is over the second.
On api lower than 21 it works : the second part take only the space between the first and the third Linearlayout.
Does anyone known why it is not working and hos to do ?
Thanks
Change the ordering to have your top and bottom view declared before the view that is in between the two:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:layout_alignParentTop="true"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/game_main_actionbar"
android:layout_above="#+id/game_main_chat_container">
</LinearLayout>
</RelativeLayout>
As mentioned, this same layout is easier to do as a LinearLayout, which specializes in stacked elements:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:orientation="vertical"
tools:context="fr.caudoux.onlinegames.activities.GameMainFragment">
<LinearLayout
android:orientation="vertical"
android:background="#ff44f0c3"
android:id="#+id/game_main_actionbar"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
<LinearLayout
android:background="#F01234"
android:orientation="vertical"
android:id="#+id/game_main_top_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:background="#ff2c3ff0"
android:orientation="vertical"
android:id="#id/game_main_chat_container"
android:layout_marginBottom="70dp"
android:layout_width="match_parent"
android:layout_height="50dp">
</LinearLayout>
</LinearLayout>
Note how only the middle element (the element that needs to fill the remaining space) has a layout_weight on it. This ensures that all remaining space is allocated to that view while the other views are of fixed height.
You cannot have both above and below set in one view. Use below on second view and then below again on last view.

Android cannot re-size LinearLayout

I've been working on an android application recently, and in the last day or so I've been working on the GUI using the eclipse layout editor. Unfortunately, I can't resize my linearlayout in any way other than the x-dimension. I can also resize it by resizing the TextView contained within it. As sushil stated, I can't control the height of my linearlayout. My code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/helpLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="top"
android:orientation="horizontal" >
<TextView
android:id="#+id/InfoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Info:"
android:textSize="35sp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Try this. Add android:fillViewport="true" to the ScrollView
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I don`t know if I understood what you want, but try to change this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
to this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
this way, it will fill the screen when size is different.

Categories

Resources