如果android:animateLayoutChanges
设置为true
,这看起来就像是一条简单的Snackbar消息,看起来相当不和谐。Snackbar将在整个动画过程中反复闪烁。从布局中删除android:animateLayoutChanges
参数可以解决这个问题,但是现在我无法享受到它的好处。如果我在子视图而不是根视图上使用android:animateLayoutChanges
,它也会起作用。
这是一个已知的问题吗?有没有办法解决它?
这是一个示例布局,它将演示显示snackbar时的问题。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
android:animateLayoutChanges="true">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottomAppBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:backgroundTint="@color/colorPrimary"
app:fabAlignmentMode="end"
app:fabCradleMargin="4dp"
app:fabCradleRoundedCornerRadius="16dp"
app:fabCradleVerticalOffset="4dp"
app:popupTheme="@style/ThemeOverlay.MaterialComponents.Light"
app:theme="@style/ThemeOverlay.MaterialComponents.Dark.ActionBar" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/colorAccent"
app:layout_anchor="@id/bottomAppBar"
app:srcCompat="@drawable/ic_add"
app:tint="@color/colorWhite" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
发布于 2021-05-23 13:04:50
看起来像是打开的窃听器。请参阅here
发布于 2021-07-30 15:43:12
也发生在我身上,仍然没有修复30/07/2021。?
如果适用,最简单的解决方法是将布局中需要动画处理的部分放在额外的FrameLayout
中,例如:
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:theme="@style/AppTheme"
<-- Other views here, FragmentContainerView, AppBarLayout, ... -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<-- Place anything that you want animated here -->
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
如果你碰巧在“无用的”FrameLayout
中有一些其他的容器视图,你可能会得到Android Studio的"UselessParent“提示,你可以在添加的FrameLayout
:tools:ignore="UselessParent"
的子级中包含这个忽略。
https://stackoverflow.com/questions/61224010
复制相似问题