底部应用栏受约束时不显示动画

时间:2018-12-16 13:38:44

标签: android xml animation material-design android-support-library

我在以下位置实现了底部的应用栏:

implementation 'com.android.support:design:28.0.0'

一切都很好,直到我将协调器布局放到在协调器布局宽度上具有match_constraint属性的约束布局中,将fab从中心移动到末端的动画将不再起作用。

单击时从头到尾翻转fab的Java代码:

 fab.setOnClickListener(v -> {
        if(navigation.getFabAlignmentMode()==BottomAppBar.FAB_ALIGNMENT_MODE_CENTER){
            navigation.setFabAlignmentMode(BottomAppBar.FAB_ALIGNMENT_MODE_END);
        }
        else {
            navigation.setFabAlignmentMode(BottomAppBar.FAB_ALIGNMENT_MODE_CENTER);
        }
    });

此XML代码将禁用动画:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.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_height="match_parent"
    android:layout_width="match_parent">


    <android.support.design.widget.CoordinatorLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent">


        <android.support.design.bottomappbar.BottomAppBar
            android:id="@+id/bottom_appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            app:backgroundTint="@color/colorPrimary"
            app:fabAlignmentMode="center"
            app:fabCradleVerticalOffset="12dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        </android.support.design.bottomappbar.BottomAppBar>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|center_horizontal"
            android:src="@drawable/search"
            app:backgroundTint="#FFFFFFFF"
            app:layout_anchor="@+id/bottom_appbar" />


    </android.support.design.widget.CoordinatorLayout>

</android.support.constraint.ConstraintLayout>

要修复此问题,我应该更改android.support.design.widget.CoordinatorLayout的属性

 android:layout_width="0dp"

收件人

android:layout_width="match_parent"

所以我的问题是:为什么会发生这种情况,并且有任何解决办法吗?

0 个答案:

没有答案