I have a very strange problem here. In the following xml section I'm trying to use include:
<!-- CONTENT -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fadingEdge="none">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="#+id/summary"
layout="#layout/view_summary"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</ScrollView>
(the section is in a main linear layout with vertical orientation and both width and height set to fill parent)
The included xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white">
<ListView android:id="#+id/news_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:cacheColorHint="#color/transparent"
android:background="#color/transparent" />
<Button android:id="#+id/news_load_more"
android:layout_width="fill_parent"
android:layout_height="40dip"
android:text="Load more..."/>
</LinearLayout>
The problem is that the ListView is not taking up the whole height (the height of the screen), only the size of one single list item. I have tried setting layout parameters from code, but it didn't helped.
Any idea is welcomed.
Thanks.
Don't put listview inside scrollview. Remove the scrollview.
Add android:layout_weight="0" to <Button android:id="#+id/news_load_more" ... /> This will tell it that <ListView android:id="#+id/news_list" ...> is the one to be expanded to fill its parent while the button must not.
Please changed android:layout_height="wrap_content" instead of android:layout_height="fill_parent"
only not changed ScrollView height property .
may be help to you.
Related
Because of the design of the app, I need to do the following:
(I reduced the problem as much as possible - and searched in other answers, but havent found my problem exactly)
As you can see in the picture, I have following components:
Listview
GreenDivider with a fixed size of 1dp
Button-Area
The Listview is on top, the button-area in the bottom and the divider between them. The Listview is variable in its size.
Following is the difficult part:
The divider has always be visible.
The divider has always to be above the button-area. If the listview does not use the entire available space, the divider has to be exactly below the listview. If the Listview uses more space than available, the divider has to be exactly above the button-area. And of course, the listview should be scrollable.
I tried a long time with relative layout and also with weight in linearlayout. If you got a solution, please share your idea with me.
The following is the part of the layout, but it actually does not work as expected:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
</LinearLayout>
<LinearLayout
android:id="#+id/divider_layout"
android:layout_width="fill_parent"
android:layout_height="1dp" >
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</LinearLayout>
Use a relative layout as your top level. set the footer to alignBottom, and the LinearLayout that contains the Listview and the separator to layout_above="#id/footer". I have edited your xml to solve your problem (I think its properly formed but SO isn't the best editor).
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:alignParentTop="true"
android:layout_above="#id/footer">
<ListView
android:id="#+id/notification_action_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navigation_item_background_selector"
android:divider="#null"
android:dividerHeight="0dp"
android:orientation="vertical" />
<include
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
layout="#layout/divider_horizontal_green" />
</LinearLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="true"
android:orientation="vertical" >
<Button
android:id="#+id/notification_action_remove_button"
style="#style/flat_button_red_rounded"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_big"
android:paddingLeft="#dimen/margin_big"
android:paddingRight="#dimen/margin_big"
android:text="#string/delete_account" />
</LinearLayout>
</RelativeLayout>
I would declare two dividers and give them each an id.
Then, programatically, I would check the size of the list view against the size of its container.
If the listview is bigger than the container I would make the divider parked above the buttons "visible" and the one below the listview "gone"
etc...
Truthfully, I'd probably just align it above the buttons and call it a day.
I've problem similar to the one here: Android ListView doesn't expand the whole screen?
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/ResultLayout">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent" android:id="#+id/ListView"
android:layout_height="fill_parent"></ListView>
</ScrollView>
<LinearLayout android:id="#+id/pagingPanel"
android:gravity="center" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal"></LinearLayout>
<Spinner android:layout_width="fill_parent" android:id="#+id/ManSpinner"
android:layout_height="fill_parent" />
</LinearLayout>
In this case, I should have a ScrollView or the PagingPanel LinearLayout will disappear.
Edit
The desired layout is to have all the elements stacked on top of each other. but if the elements exceed the page height, a scroll should be added to the ListView.
If you have a vertical LinearLayout, You can't have multiple fill_parent for layout_height of your LinearLayout elements. What layout you would like to achieve? Uniformly divide screen for all elements?
Another problem is that using ListView in ScrollView is not a good idea also because ListView itself is scrollable.
You should write what layout you would like to achieve with your XML. Also generally is a good practice to write your XML in multiple steps and iterate to woking solution layout by layout.
EDIT: Ok, try something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ResultLayout">
<ListView android:id="#+id/ListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout android:id="#+id/pagingPanel"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<Spinner android:id="#+id/ManSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
I want to have a site, which contains of a vertical layout, that has a content part and a footer part. The footer part should be 20% of the height of the display height. I think that it is a very common usecase.
I have tried some ways, but was not successful in the end.
How would i implement this?
TU in advance!
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="-1">
<LinearLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="20"/>
<LinearLayout
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="60"/>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="20"/>
</LinearLayout>
This should give you a header and footer that take 20% of the space, with the body occupying 60%. See http://developer.android.com/reference/android/widget/LinearLayout.html#setWeightSum(float) for a simple description of what this is doing.
This is what worked for me to display a footer with ads.
<LinearLayout>
<LinearLayout xmlns:myapp="http://schemas.android.com/apk/res/com.broschb.wiiscale"
android:layout_width="fill_parent" android:layout_marginTop="5px"
android:layout_below="#+id/weight" android:layout_height="fill_parent"
android:gravity="center_horizontal|bottom">
<myFooterComponents android:layout_width="fill_parent" android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
LinearLayout, right? Just set the height of both your content and footer layouts to fill_parent, and give the content area a layout_weight of 8, and the footer a layout_weight of 2.
Hi all
my need is that buttons must show at bottom, so my code as
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="12dip">
<ListView
android:id="#+id/list_multiselectable"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical">
</ListView>
<LinearLayout android:orientation="horizontal"
android:background="#android:drawable/bottom_bar"
android:paddingLeft="4.0dip" android:paddingTop="5.0dip"
android:paddingRight="4.0dip" android:paddingBottom="1.0dip"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
my buttons code here
</LinearLayout>
</LinearLayout>
But when items in list are less (until scroll bar of list view is not enable), Buttons are visible, but when items in list are more, buttons are not visible, although I scrolled list item to last row, but at last buttons are not displaying. How can I solve it.
Thank you!
LinearLayout is giving ListView all the space it needs, because it considers its children sequentially and doesn't take into account those that follow.
My suggestion is to use RelativeLayout.
<RelativeLayout ...>
<ListView ...
android:id="#+id/list"
android:layout_alignParentTop="true"/>
<LinearLayout ...
android:layout_below="#id/list"
android:layout_alignParentBottom="true">
...buttons...
</LinearLayout>
</RelativeLayout>
I am not sure. But you may try to set the weight of your listview.
<ListView
android:id="#+id/list_multiselectable"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:layout_gravity="center_vertical">
</ListView>
You can set the minimumheight of listview
e.g. 320*480
listview height = 430
button's layout height = 50
I have a problem with the ListView in Android.
When I set android:layout_height="wrap_content", ListView stays just one or two rows long and I can't find a way to make him "wrapped".
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:id="#+id/question"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView android:id="#+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</FrameLayout>
Is there any way to accomplish this? Thanks in advance!
You should never set the height of a ListView to wrap_content. Either set the height to fill_parent or do something like this:
<ListView
android:layout_height="0dp"
android:layout_weight="1"
/>
Source: http://www.youtube.com/watch?v=wDBM6wVEO70&t=40m45s
It appears you're trying to add a header to your listview. Listview has built-in support for headers (and footers). The method for setting a header is listview.addHeader(View view). You can customize the header as needed.
use ExpandableHeightGridView.java of gitHub ExpandableHeightGridView Try for scrollview