【问题标题】:View jumps and blinks instantly, though animateLayoutChanges="true"尽管 animateLayoutChanges="true" 视图会立即跳跃和闪烁
【发布时间】:2016-07-11 09:57:11
【问题描述】:

我正在 AppBarLayout 中使用 android:animateLayoutChanges="true" 制作我的 TabLayout 动画。但是当我设置 TabLayout.setVisibility(View.GONE) 时,我的片段容器会在几毫秒内立即上升到 ActionBar。然后它返回到 TabLayout 的末尾,并随之上升到 ActionBar。我在下面的 gif 中解释了这一点。

按钮 TheoryPractice 出于某种原因在 TabLayout 后面,但是当隐藏 TabLayout 动画启动 FrameContainer 时,我的视图坚持TabLayout 的底部。

我录制了一段视频来演示这种行为。 Dropbox 视频播放器跳过一些帧,动画看起来不错。这就是为什么,要注意这个错误,您可以在计算机上加载视频并以高质量观看 5 秒和 11 秒。 Video

我的 LayoutXML:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<SurfaceView
    android:layout_width="0px"
    android:layout_height="0px"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:animateLayoutChanges="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/>


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:visibility="gone"
        app:tabGravity="fill"
        app:tabIndicatorColor="@android:color/white"
        app:tabMode="fixed"/>

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

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <!--
        This FrameLayout holds my fragments.
    -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/outer_background">

        <ProgressBar
            android:id="@+id/main_load_progress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:indeterminate="true"/>
    </FrameLayout>

    <include
        android:id="@+id/left_drawer_full"
        layout="@layout/navigation_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"/>

</android.support.v4.widget.DrawerLayout>

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

此外,我正在使用 23.2.1 支持库

如何解决这种闪烁和跳跃问题?

【问题讨论】:

    标签: android android-fragments android-animation material-design android-appbarlayout


    【解决方案1】:

    尝试将android:animateLayoutChanges="true" 添加到您的视图中

    app:layout_behavior="@string/appbar_scrolling_view_behavior
    

    这就是你的 DrawerLayout。然后在其上启用转换类型LayoutTransition.CHANGING,如下所示:

    ViewGroup layout = (ViewGroup) findViewById(R.id. drawer_layout);
    LayoutTransition layoutTransition = layout.getLayoutTransition();
    layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
    

    相关:https://stackoverflow.com/a/22573099/1363742

    【讨论】:

      【解决方案2】:

      我浪费了一整天的时间来调查这个问题。 我已经找到了解决这个问题的一种可能的方法。 现在我通过这段代码改变可见性

      mTabLayout.postDelayed(new Runnable() {
              @Override
              public void run() {
                  switch (newMode) {
                      case MODE_CONTENTS:
                          mTabLayout.setVisibility(mContents.isTheoryAvailable() ? View.VISIBLE : View.GONE);
                          break;
                      default:
                          findViewById(R.id.content_frame).setVisibility(View.INVISIBLE);
                          mTabLayout.setVisibility(View.GONE);
                          findViewById(R.id.content_frame).setVisibility(View.VISIBLE);
                  }
              }
          }, 200);
      

      它运行良好,视图现在不闪烁。但是在旧的机器人上,这个错误仍然存​​在。

      【讨论】:

        猜你喜欢
        • 2019-12-06
        • 2021-12-03
        • 2015-11-25
        • 1970-01-01
        • 2013-10-19
        • 2016-07-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多