首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如果根布局上的android:animateLayoutChanges为true,则Snackbar闪烁

如果根布局上的android:animateLayoutChanges为true,则Snackbar闪烁
EN

Stack Overflow用户
提问于 2020-04-15 16:00:41
回答 2查看 243关注 0票数 6

如果android:animateLayoutChanges设置为true,这看起来就像是一条简单的Snackbar消息,看起来相当不和谐。Snackbar将在整个动画过程中反复闪烁。从布局中删除android:animateLayoutChanges参数可以解决这个问题,但是现在我无法享受到它的好处。如果我在子视图而不是根视图上使用android:animateLayoutChanges,它也会起作用。

这是一个已知的问题吗?有没有办法解决它?

这是一个示例布局,它将演示显示snackbar时的问题。

代码语言:javascript
运行
复制
<?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>
EN

回答 2

Stack Overflow用户

发布于 2021-05-23 13:04:50

看起来像是打开的窃听器。请参阅here

票数 1
EN

Stack Overflow用户

发布于 2021-07-30 15:43:12

也发生在我身上,仍然没有修复30/07/2021。?

如果适用,最简单的解决方法是将布局中需要动画处理的部分放在额外的FrameLayout中,例如:

代码语言:javascript
运行
复制
<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“提示,你可以在添加的FrameLayouttools:ignore="UselessParent"的子级中包含这个忽略。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61224010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档