Listview with a button at the bottom of the android studio list

Asked

Viewed 784 times

0

Good afternoon, I have a Listview that is bringing some data, this working smoothly. But at the end of the list, I need to put a button. This button should not repeat itself, as it is happening. I put it inside the layout xml of the list.

  • 1

    Please post your . xml file with the layout, it will help to understand the problem and come up with a solution.

2 answers

0


You should use a Float Button and isolate your Listview in a Linear Layout, example:

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/ic_action_add" />

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:fitsSystemWindows="true">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null" />

</LinearLayout>

The line:

android:layout_gravity="bottom|end"

You will be responsible for leaving the Float Button there in the lower right corner once.

0

you have to create a relative layout, and then you put the button down, then put the list, but with the tag above, so first enter the butao and then the list that has to be on top of the button

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    xmlns:tools="http://schemas.android.com/tools">

    <Button
         android:id="@+id/button"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="bottom" 
         android:layout_alignParentBottom="true" />

     <ListView
         android:id="@+id/list"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:divider="@null"
         android:layout_above="@id/button" />

 </RelativeLayout>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.