3

Is there any way to have a button directly below a listview, so that as the listview grows, the button moves down BUT the button is never pushed off screen. IE, once the listview has outgrown the screen, the button is still always visible, and the listview is scrollable.

I have managed to make the button ALWAYS at the bottom of the screen, but i want it to sit up directly below the listview while the listview is smaller than the screen.

I have tried using various arrangements of relative and linear layouts and using the weight property, and things that seem like they should work simply don't, so it might be worth checking any answers before posting.

CLARIFICATION: To phrase it in a different way: I want a button to sit below a listview, moving down as it grows, but i dont want the button to be pushed offscreen

Sam
  • 3,453
  • 1
  • 33
  • 57
  • 1
    Did you take a look at this: http://stackoverflow.com/questions/5487552/limit-height-of-listview-on-android . What the solution tries to do is to have the button at the bottom of the list always, but when it grows out of the screen, its height gets limited by the weight. – Urban Sep 13 '12 at 22:55
  • yes! that works, unbeliveably! my layout is totally rediculous now (http://imgur.com/c9L1Z queue inception soundtrack...) hence why i never tried this solution. Thank-you for pointing this out. – Sam Sep 13 '12 at 23:14
  • answer with that comment and ill vote you as the answer. – Sam Sep 13 '12 at 23:15
  • Glad to hear that. Ill add it as an answer. Infact even I was very curious how this would be done. – Urban Sep 14 '12 at 09:15

2 Answers2

2

This previous post does exactly what you want to do. What it does basically is that it keeps the button at the bottom of the list at all times. But when the list grows out of the screen area, its height gets limited by the weight parameter.
This way, the list's bottom edge is just above the button's LinearLayout and you get the same behavior that you were looking for.

Community
  • 1
  • 1
Urban
  • 2,201
  • 24
  • 52
  • I posted a much cleaner solution based on the above link. Check out the community wiki solution on that post - http://stackoverflow.com/a/24284354/383414 – Richard Le Mesurier Jun 18 '14 at 11:32
1

If You Want to show this button in the end of list item. Then use this code

final Button btnAddMore = new Button(this);
btnAddMore.setText(R.string.art_btn_moreIssues);
exArticlesList = (ExpandableListView) this.findViewById(R.id.art_list_exlist);
exArticlesList.addFooterView(btnAddMore);

OR If you show button in your layout end then use this code.

<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/btn_New" >
</ListView>

<Button
    android:id="@+id/btn_New"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="20dp"
    android:text="@string/New"
    android:width="170dp"
    android:layout_alignParentBottom="true" />
  </RelativeLayout>
Md.Tarikul Islam
  • 1,241
  • 1
  • 14
  • 16