英文:
how can i align my floating button to the bottom of the page in android studio
问题
[1]: https://i.stack.imgur.com/OvP4P.png
// 父视图 ScrollView
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
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>
</ScrollView>
英文:
//Parent View
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/back4">
//Relative Layout Child of ScrollView
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="40dp">
//Grid View with Parent Relative Layout. Grid View not allowing floating button to align bottom
<GridView
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="50dp">
</GridView>
//Floating Button adding to Bottom of screen
<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"/>
//End of Relative Layout
</RelativeLayout>
//End of Scroll View
</ScrollView>
答案1
得分: 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" />
另外,不需要使用垂直滚动的ScrollView,因为GridView也是一个垂直滚动的小部件(GridView)。
英文:
Make some changes to your FloatingActionButton XML. Hope this works for you!
<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" />
Also, there is no need of vertically scrolling ScrollView as GridView is also a vertically scrolling widget(GridView).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论