android - BottomAppBar 忽略“layout_gravity”,始终显示在顶部
问题描述
我正在尝试在BottomAppBar
我的应用程序中实现 a 并且无法制作 FAB 或BottomAppBar
在底部显示。这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".dashboard.DashboardActivity">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_white_24dp"
app:layout_anchor="@id/bottom_bar"/>
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/mtrl_bottomappbar_height"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimary"
app:fabAttached="true"
app:fabCradleVerticalOffset="12dp"
app:fabAlignmentMode="center"/>
</android.support.constraint.ConstraintLayout>
但是,这就是模拟器中显示的内容:
如何在底部对齐?
解决方案
首先,将布局更改为 LinearLayout 并将方向定义为垂直,然后将您的代码放在另一个 LinearLayout 中,您可以在其中设置它的 marginTop ,因为您的要求只是进行这些更改它应该可以正常工作
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".dashboard.DashboardActivity"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="330dp" //mark height accordingly
>
\\put your code here
</LinearLayout>
</LinearLayout>
试试这个应该适合你
推荐阅读
- jquery - 在网页上的文本输入字段中输入的 0 被重置为 null
- vue.js - 导入声明在 Laravel-6 中的 Vue app.js 文件中不起作用,编辑器 PHP Storm(我想导入 vue-router)
- mysql - 在 Azure Web-App + MySQL 上托管 Laravel 5.8
- java - 在Java中将time4j的中文转换日期格式化为公历
- python - df.set_index() 没有按我的预期工作
- c - 静态变量内存位置
- python - 使用 bounding_box 收集 Twitter 流
- python - 将十进制转换为二进制的函数中的未知错误
- python - 如何使用 GridSearchCV 找到 GBR 的最佳参数?
- android - 使用 setCurrentItem 打开幻灯片时,Viewpager2 转换卡住了一半