简体   繁体   English

当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?

So I am trying to make a layout like this : 所以我试图做这样的布局:

在此处输入图片说明

One way to do that is to use a bottom app bar Anatomy , but the thing with bottom app bar is that it can be only used within a coordinate layout. 一种实现方法是使用底部应用程序栏Anatomy ,但是具有底部应用程序栏的是它只能在坐标布局中使用。 But I want to have a listview or say any other views above it so I am using a constraint layout and then adding coordinate layout with bottom app bar and fab, the thing is that when I set the height of coordinate layout to wrap content in order to make space above it for other views it hides half of the FAB { floating action button ) but on setting coordinate layout height to match_parent shows the full FAB, now when I'll use match_parent as height it will replace constraint layout and I'll be no longer be able to normally use constraint layout for adding other views, so how can I make the height of constraint layout to wrap_content while showing the complete FAB 但是我想要一个listview或上面有其他视图,所以我使用约束布局,然后在底部的应用栏和fab中添加坐标布局,问题是当我设置坐标布局的高度以按顺序包装内容时为了在其他视图上方腾出空间,它会隐藏FAB的一半(浮动动作按钮),但是在将坐标布局高度设置为match_parent时会显示完整的FAB,现在当我将match_parent用作高度时,它将替换约束布局,并且不再能够正常使用约束布局来添加其他视图,因此如何在显示完整的FAB时使约束布局的高度达到wrap_content

Here is the code [XML] which I want to use but is not producing desired results as it hiding half of the FAB 这是我要使用的代码[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>

It gives me something like this (1st) : 它给了我这样的东西(第一):

在此处输入图片说明

but I want this ( 2nd ): 但我想要这个(第二个):

https://media.discordapp.net/attachments/597356915219103745/617762091134222366/fab1.png?width=165&height=300

for achieving something like image 2 I'' have to set the height of coordinatorlayout to match_parent but I want the coordinator layout to just be as big as the space taken by it's children, how can I do that ? 为了实现如图2所示的效果,我必须将coordinatorlayout的高度设置为match_parent,但是我希望协调器布局与孩子所占用的空间一样大,我该怎么做?

Try something like below... I had similar case and this one helped me.. 尝试以下类似方法...我有类似的案例,这个案例对我有所帮助。

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM