Search code examples
javaandroidlistviewscrollviewandroid-framelayout

I'm using a framelayout and inside it I want a listview and a floating action button, but the listview doesn't extend


Why is this not working? It's a problem with the listview. I've tried in many ways and ending up with the button not showing

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.notes.NotesFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <ListView
                android:id="@+id/listView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <com.google.android.material.floatingactionbutton.FloatingActionButton
                android:id="@+id/fab_add"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end|bottom"
                android:src="@drawable/ic_baseline_add_24" />
        </LinearLayout>
    </ScrollView>

</FrameLayout>```

Solution

  • The first problem is that you cannot put a ListView inside a ScrollView, ListView itself is scrollable and the second problem it's with the margin if you use a bottom menu, I also encountered this problem. Try this one

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".fragments.notes.NotesFragment">
    
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
    
                <ListView
                    android:id="@+id/listView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
    
                <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@+id/fab_add"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentEnd="true"
                    android:layout_alignParentBottom="true"
                    android:layout_gravity="bottom|end"
                    android:layout_marginRight="20dp"
                    android:layout_marginBottom="70dp"
                    android:src="@drawable/ic_baseline_add_24" />
            </RelativeLayout>
    
    </FrameLayout>```