java - 我正在使用框架布局,在其中我想要一个 ListView 和一个 float 操作按钮,但 ListView 不会扩展

标签 java android listview scrollview android-framelayout

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>```

最佳答案

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>```

关于java - 我正在使用框架布局,在其中我想要一个 ListView 和一个 float 操作按钮,但 ListView 不会扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66676970/

相关文章:

java - 一旦调用构造函数,我可以使对象不可变吗?

java - 如何找到给定 this 的最大模数

android - 关于 AsyncTask.get()

Android:TextInputLayout - 自定义提示、底线和错误消息的颜色

java - ListView 单元格变得比它们包含的节点更大

java - 在 netbeans 中的尖括号之间拆分传入数据

java - 命名谓词

安卓自签名证书 : Trust anchor for certification path not found

java - 添加用于取消 ListView 中选择的监听器 (JavaFX)

java - 如何在单击自定义 ListView 中的按钮时特别更改一行 TextView 值?