Search code examples
androidandroid-layoutandroid-listviewandroid-viewandroid-button

Have a button floating in front of a List View


I would like to have a button permanently floating on top of a scrollable ListView in a fragment. I have tried using FrameLayouts, LinearLayout, RelativeLayout and more, but nothing will work.

Here is my base code I'm working off:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<!--        New Project Button-->
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_margin="5dp"
    android:id="@+id/fragment_profile_project_relLayoutButton">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/fragment_profile_project_newProject_button"
        android:layout_alignParentRight="true"
        android:paddingHorizontal="15dp"
        android:text="@string/project_new_project_button"
        android:background="@drawable/white_rounded_button"/>
</RelativeLayout>

<!--        List View-->
<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragment_profile_project_listView"
    android:layout_marginBottom="50dp"/>

The Android Studio design view 'understands' what I'm trying to do, but when I run the app only the New Project button appears, or nothing.

enter image description here

Anyone know how to get a floating button in front of a ListView?

Thanks,

Alex


Solution

  • Move the ListView Above the RelativeLayout with the button. The top view in a layout is the view at the bottom of the layout so moving the listview to the top of the layout file makes it the bottom view