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
Related
I want to achieve this
I am doing this
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/upper"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/wallet_dim_foreground_inverse_disabled_holo_dark">
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:layout_below="#+id/upper"
android:background="#color/blueAccentColor">
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/upper"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/lower"
android:background="#color/wallet_dim_foreground_inverse_disabled_holo_dark">
</LinearLayout>
<LinearLayout
android:id="#+id/lower"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:background="#color/blueAccentColor"></LinearLayout>
</RelativeLayout>
You have to set the first Layout to be above the seconde.
With the code you provided you will have a top layout taking all space, and a bottom layout being below him. If you think about it you can see that it's logic that the result will be different.
If you remove android:layout_below="#+id/upper"and add android:layout_alignParentBottom="true"from the lower one, this Layout will be anchored to the bottom side, whichever the screen size is.
Than adding android:layout_above="#+id/lower" to the top Layout, he will take all space(thanks to android:layout_height="fill_parent") but it will stay above the lower Layout.
Here is the result you want :)
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.
http://realdevs.tistory.com/entry/asdf
↑ Picture.
I have a problem when I use ListView.
As the screen is full of widgets, I would like the ListView's items to be scrolled with other items in the layout.
On the picture, the blue one is a widget on the layout, and the red ones are the items of ListView.
When I scroll up the items, they move, but the blue one doesn't.
How can I make it to move together with ListView as it is an item in ListView?
you an add your blue layout as your listView header.
this will help you in adding a layout as header.
Simply add that blue part in scrollview
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
your layout
........
</ScrollView>
From your pic in http://realdevs.tistory.com/entry/asdf
I'm implement in coding xml this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#e0e0e0"
android:orientation="vertical" >
<!-- this layout add your other items. I'm exam add Button -->
<Button
android:id="#+id/butonTop"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:text="Top Button" />
</LinearLayout>
<!-- ListView in bottom screen and can auto scroll. -->
<ListView
android:id="#+id/dataListView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:drawSelectorOnTop="false" >
</ListView>
</LinearLayout>
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.
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.