视图立即跳跃和闪烁,尽管 animateLayoutChanges="true"
View jumps and blinks instantly, though animateLayoutChanges="true"
我正在使用 android:animateLayoutChanges="true" 在 [=29] 中制作我的 TabLayout 动画=]AppBarLayout。但是当我设置 TabLayout.setVisibility(View.GONE) 时,我的片段的容器立即上升到 ActionBar 几毫秒.然后它 returns 到 TabLayout 的末尾,并随着它上升到 ActionBar。我在下面的 gif 中解释了这一点。
按钮 Theory 和 Practice 出于某种原因位于 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 支持库。
如何解决这个闪烁和跳跃问题?
我浪费了一整天的时间来调查这个问题。
我已经找到了解决这个问题的一种可能的方法。
现在我通过此代码更改可见性
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);
效果很好,视图现在不闪烁了。但是在旧的机器人上,这个错误仍然存在。
尝试使用
将android:animateLayoutChanges="true"
添加到您的视图中
app:layout_behavior="@string/appbar_scrolling_view_behavior
这就是您的 DrawerLayout。然后启用 Transition Type LayoutTransition.CHANGING
像这样:
ViewGroup layout = (ViewGroup) findViewById(R.id. drawer_layout);
LayoutTransition layoutTransition = layout.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
相关:
我正在使用 android:animateLayoutChanges="true" 在 [=29] 中制作我的 TabLayout 动画=]AppBarLayout。但是当我设置 TabLayout.setVisibility(View.GONE) 时,我的片段的容器立即上升到 ActionBar 几毫秒.然后它 returns 到 TabLayout 的末尾,并随着它上升到 ActionBar。我在下面的 gif 中解释了这一点。
按钮 Theory 和 Practice 出于某种原因位于 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 支持库。
如何解决这个闪烁和跳跃问题?
我浪费了一整天的时间来调查这个问题。 我已经找到了解决这个问题的一种可能的方法。 现在我通过此代码更改可见性
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);
效果很好,视图现在不闪烁了。但是在旧的机器人上,这个错误仍然存在。
尝试使用
将android:animateLayoutChanges="true"
添加到您的视图中
app:layout_behavior="@string/appbar_scrolling_view_behavior
这就是您的 DrawerLayout。然后启用 Transition Type LayoutTransition.CHANGING
像这样:
ViewGroup layout = (ViewGroup) findViewById(R.id. drawer_layout);
LayoutTransition layoutTransition = layout.getLayoutTransition();
layoutTransition.enableTransitionType(LayoutTransition.CHANGING);
相关: