//父视图
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/back4">
// ScrollView的相对布局子级
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp">
//具有父级相对布局的网格视图。网格视图不允许浮动按钮与底部对齐
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="50dp">
</GridView>
//浮动按钮添加到屏幕底部
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addNew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/gridview"
android:layout_alignParentEnd="true"
android:src="@drawable/addbutton"/>
//相对布局结尾
</RelativeLayout>
//滚动视图结束
答案 0 :(得分:2)
对FloatingActionButton XML进行一些更改。希望这对您有用!
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/addNew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="@drawable/addbutton" />
此外,由于GridView也是垂直滚动小部件(GridView),因此不需要垂直滚动ScrollView。