Android BottomAppBar忽略';布局图';,始终显示在顶部
我试图在我的应用程序中实现Android BottomAppBar忽略';布局图';,始终显示在顶部,android,android-layout,Android,Android Layout,我试图在我的应用程序中实现BottomAppBar,但无法在底部显示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/
BottomAppBar
,但无法在底部显示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>
如何在底部对齐?有时它也取决于您的根布局。
对于ConstraintLayout,请尝试app:layout\u constraintBottom\u toBottomOf=“parent”
请检查其他布局。有时它也取决于您的根布局。
对于ConstraintLayout,请尝试app:layout\u constraintBottom\u toBottomOf=“parent”
对于其他布局也请检查此项。ConstraintLayout不使用布局重力。相反,请使用:
app:layout_constraintBottom_toBottomOf="parent"
没有边距。约束视图不使用布局重力。相反,请使用:
app:layout_constraintBottom_toBottomOf="parent"
无边距。首先,将布局更改为LinearLayout,并将方向定义为垂直方向,然后将代码放入另一个LinearLayout中,您可以根据需要在其中设置边距
只要做这些改变,它就可以正常工作
<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,并将方向定义为垂直,然后将代码放在另一个LinearLayout中,您可以根据需要在其中设置边距
只要做这些改变,它就可以正常工作
<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作为我的根布局…不要发布代码blob作为答案,而不解释更改的内容和原因。从教育角度看,这是非常无用的是的,对不起,伙计,我真的不想使用线性布局作为我的根布局…有没有答案对你有用?如果有用你应该接受答案对你有用吗?如果有用你应该接受谢谢,事实上,我最终将我的FAB和BottomAppBar包装成了一个协调的布局。使用您的代码片段对BottomAppBar有效,但FAB不会附加我尝试的任何内容。谢谢,实际上,我最终将我的FAB和BottomAppBar包装在一个协调布局中。使用您的代码片段对BottomAppBar有效,但FAB不会附加我尝试的任何内容。