当 CL 的高度设置为 wrap_Content 时,为什么坐标布局 ( CL ) 隐藏了一半的浮动操作按钮?
Why is Coordinate layout ( CL )hiding half of the floating action button when the height of CL is set to wrap_Content?
所以我正在尝试制作这样的布局:
一种方法是使用底部应用栏 Anatomy,但是底部应用栏的问题是它只能在坐标布局中使用。但是我想要一个列表视图或者说它上面的任何其他视图所以我使用约束布局然后添加带有底部应用程序栏和 fab 的坐标布局,问题是当我设置坐标布局的高度以按顺序包装内容时使 space 在其他视图上方,它隐藏了一半的 FAB {浮动操作按钮)但是在将坐标布局高度设置为 match_parent 时显示完整的 FAB,现在我将使用 match_parent 作为高度,它将取代约束布局,我将不再能够正常使用约束布局来添加其他视图,因此如何在显示完整的 FAB[= 时将约束布局的高度设置为 wrap_content 17=]
这是我想使用的代码 [XML],但没有产生预期的结果,因为它隐藏了一半的 FAB
<androidx.constraintlayout.widget.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"
android:background="@color/colorAppWhite"
tools:context=".ActivityFive">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/af_bn"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorWaarkDB1"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="16dp">
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:elevation="16dp"
app:fabSize="normal"
app:layout_anchor="@+id/af_bn" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
它给了我这样的东西(第 1 个):
但我想要这个(第二个):
为了实现类似图 2 的效果,我必须将 coordinatorlayout
的高度设置为 match_parent,但我希望协调器布局与拍摄的 space 一样大它是 children,我该怎么做?
试试下面的方法...我有类似的案例,这个帮助了我..
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".controller.MainActivity">
<include layout="@layout/content_listview_here"/>
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
app:backgroundTint="#E3E3E3"
app:hideOnScroll="false"
app:fabAlignmentMode="center"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home_white"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar" />
</android.support.design.widget.CoordinatorLayout>
所以我正在尝试制作这样的布局:
一种方法是使用底部应用栏 Anatomy,但是底部应用栏的问题是它只能在坐标布局中使用。但是我想要一个列表视图或者说它上面的任何其他视图所以我使用约束布局然后添加带有底部应用程序栏和 fab 的坐标布局,问题是当我设置坐标布局的高度以按顺序包装内容时使 space 在其他视图上方,它隐藏了一半的 FAB {浮动操作按钮)但是在将坐标布局高度设置为 match_parent 时显示完整的 FAB,现在我将使用 match_parent 作为高度,它将取代约束布局,我将不再能够正常使用约束布局来添加其他视图,因此如何在显示完整的 FAB[= 时将约束布局的高度设置为 wrap_content 17=]
这是我想使用的代码 [XML],但没有产生预期的结果,因为它隐藏了一半的 FAB
<androidx.constraintlayout.widget.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"
android:background="@color/colorAppWhite"
tools:context=".ActivityFive">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/af_bn"
style="@style/Widget.MaterialComponents.BottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:backgroundTint="@color/colorWaarkDB1"
app:fabAlignmentMode="center"
app:fabCradleRoundedCornerRadius="16dp">
</com.google.android.material.bottomappbar.BottomAppBar>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_black_24dp"
app:elevation="16dp"
app:fabSize="normal"
app:layout_anchor="@+id/af_bn" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
它给了我这样的东西(第 1 个):
但我想要这个(第二个):
为了实现类似图 2 的效果,我必须将 coordinatorlayout
的高度设置为 match_parent,但我希望协调器布局与拍摄的 space 一样大它是 children,我该怎么做?
试试下面的方法...我有类似的案例,这个帮助了我..
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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=".controller.MainActivity">
<include layout="@layout/content_listview_here"/>
<android.support.design.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom"
app:backgroundTint="#E3E3E3"
app:hideOnScroll="false"
app:fabAlignmentMode="center"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_home_white"
app:backgroundTint="@color/colorPrimary"
app:fabSize="normal"
app:layout_anchor="@id/bottomAppBar" />
</android.support.design.widget.CoordinatorLayout>