锚定物料浮动操作按钮

时间:2020-06-22 09:49:34

标签: android android-layout material-design floating-action-button

layout_anchor与“材质操作”按钮不起作用。是否有其他适当的方法将其锚定到布局。我浏览了Fab文档Material Design Floating Action Button,但是我找不到锚定Button的任何正确方法。

下面的代码之前可以正常工作,但是在SDK更新中无法正常运行。 layout_anchor属性使按钮消失,但是可以在XML编辑器中看到按钮位于UI的空白处。

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/settings"
    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:fitsSystemWindows="true"
    tools:context=".SatActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_barsettings"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="@dimen/app_bar_height"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout_settings"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleGravity="bottom"
            android:background="@drawable/side_nav_bar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar_settings"
                android:layout_width="match_parent"
                android:background="@android:color/transparent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay"/>

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

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab_log_out"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchorGravity="bottom|end"
        app:layout_anchor="@id/app_bar_layout_settings"
        android:src="@drawable/ic_light_logout"/>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

这是Gradle文件

compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
    minSdkVersion 22
    targetSdkVersion 29
    versionCode 1
    versionName '1.0.0'
}

0 个答案:

没有答案