1

I want to make to the listView with an increase fell button: Drawing of what I want

My attempt at implementing this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#214075"
    android:layout_height="match_parent"
    android:orientation="vertical" >



    <ListView
        android:id="@+id/listbascet"
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
            android:layout_weight="1" />

    <Button
        android:id="@+id/sendtoEmail"
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_weight="0"
        android:text="Заказать услуги" />

</LinearLayout>
tilpner
  • 4,351
  • 2
  • 22
  • 45
pot34731
  • 191
  • 9
  • so you want to add elements to the listview? – Sebastian Walla May 03 '15 at 11:39
  • what result you get from the xml? I recommend to use RelativeLayout in this case. Make sure Button is below the Listview by using android:layout_below="@+id/your_list_view_id". And you set the layout_height for ListView to 0dip, it means you don't want to show it? I think you would like to set it to wrap_content – Surely May 03 '15 at 11:39
  • Inlined picture, removed greeting-ish stuff. – tilpner May 03 '15 at 12:07
  • @xwhyLikeThis its result my xml http://s22.postimg.org/ygpo9g169/image.png – pot34731 May 03 '15 at 12:46
  • @SebastianWalla yes, i want add element to listView, and button lower down – pot34731 May 03 '15 at 12:48
  • Try @xwhyLikeThis suggestion. Change your overall layout type from `LinearLayout` to `RelativeLayout`, set height to `wrap_content`, and set your button to `layout_below` your `ListView` – PPartisan May 03 '15 at 13:00
  • @pot34731I see the problem, this result in the button been always fell to bottom right? I think the problem is you set android:layout_weight="1" for the listview. According to android document, layout_weight for listview bigger than the button means the listview will always expand to take up the rest space in the screen. So maybe you just remove the layout_weight property for both of the views. – Surely May 03 '15 at 13:12
  • Can you remove android:layout_weight="0" from Button and see what result you get ? – Zealous System May 04 '15 at 06:23

1 Answers1

1

You would better remove the button from the XML and add it to another one.

Then you can use the inflate to get the button and add it as footer view to the original list view.

This way it will be at the end of the list and scroll will it as well!

How to inflate:

LayoutInflater inflater = (LayoutInflater) 
                     getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.mylayout, null);

Button item = (Button) view.findViewById(R.id.item); // how to reference your button

How to add footer:

listView.addFooterView(view); // view is the inflated layout.

More details about footer view contained in this answer as well.

Community
  • 1
  • 1
madlymad
  • 6,367
  • 6
  • 37
  • 68