start"

问题描述 投票:0回答:1
instead of

layout_constraintBottom_toBottomOf

to fix your FAB at the bottom

如何在普通的CoordinatorLayout中修复FAB中的Fragment?

我想知道在这种情况下,如何处理视图(如浮动动作按钮)的最佳或更好的做法。

遇到的问题

目前,我实现了一个普通的ToolBar,它可以在Activity中隐藏或出现,以便在某些Fragment中显示,然后我想在某个Fragment中实现一个FAB,但当我在Fragment中实现一个FAB时,它移动了ToolBar的高度。

失败图像

我想...

我想把它固定在屏幕的底部和右侧。

如何解决这个问题呢,如果你不介意,请告诉我这个问题。

我想...

我的想法

我认为FAB应该放在Activity.如果事情进展顺利,我想根据Fragment改变可见性和不同的角色。

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <com.google.android.material.appbar.AppBarLayout       
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        >

        <androidx.appcompat.widget.Toolbar         
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"           
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </com.google.android.material.appbar.AppBarLayout>

    <fragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

我的英语不好,但我很感激你的好意。


<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            -- some constraints--
            android:layout_margin="16dp"/>
</<androidx.constraintlayout.widget.ConstraintLayout>
代码(节选)
android android-fragments kotlin floating-action-button android-coordinatorlayout
1个回答
0
投票

如何在普通的CoordinatorLayout中修复FAB,我想知道在这种情况下如何处理视图(如浮动动作按钮)的最佳或更好的做法。问题 目前,我实现了一个 ...使用 android:layout_gravity="底部

© www.soinside.com 2019 - 2024. All rights reserved.