[英]Why is Coordinate layout ( CL )hiding half of the floating action button when the height of CL is set to wrap_Content?
所以我试图做这样的布局:
一种实现方法是使用底部应用程序栏Anatomy ,但是具有底部应用程序栏的是它只能在坐标布局中使用。 但是我想要一个listview或上面有其他视图,所以我使用约束布局,然后在底部的应用栏和fab中添加坐标布局,问题是当我设置坐标布局的高度以按顺序包装内容时为了在其他视图上方腾出空间,它会隐藏FAB的一半(浮动动作按钮),但是在将坐标布局高度设置为match_parent时会显示完整的FAB,现在当我将match_parent用作高度时,它将替换约束布局,并且不再能够正常使用约束布局来添加其他视图,因此如何在显示完整的FAB时使约束布局的高度达到wrap_content
这是我要使用的代码[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>
它给了我这样的东西(第一):
但我想要这个(第二个):
为了实现如图2所示的效果,我必须将coordinatorlayout
的高度设置为match_parent,但是我希望协调器布局与孩子所占用的空间一样大,我该怎么做?
尝试以下类似方法...我有类似的案例,这个案例对我有所帮助。
<?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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.