Android WebView在设备上设置视图动画时闪烁错误
我正在尝试实现滑入式导航(Facebook、Path或Google+Android应用程序)。复制此错误的完整源代码 但是,当在屏幕外设置Android WebView在设备上设置视图动画时闪烁错误,android,android-emulator,android-webview,android-animation,Android,Android Emulator,Android Webview,Android Animation,我正在尝试实现滑入式导航(Facebook、Path或Google+Android应用程序)。复制此错误的完整源代码 但是,当在屏幕外设置WebView动画时,在设备上会出现闪烁,就好像设备在将其推出屏幕之前正在咬我的WebView 该工件不会出现在模拟器上!动画进展顺利 有趣的是,这种闪烁似乎只发生在正在设置动画的视图是WebView时!下面是使用TextView作为主内容视图的同一个项目 web视图活动的布局: <RelativeLayout xmlns:android="htt
WebView
动画时,在设备上会出现闪烁,就好像设备在将其推出屏幕之前正在咬我的WebView
该工件不会出现在模拟器上!动画进展顺利
有趣的是,这种闪烁似乎只发生在正在设置动画的视图是WebView
时!下面是使用TextView作为主内容视图的同一个项目
web视图活动的布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue" >
<WebView
android:id="@+id/web_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/blue" >
<TextView
android:id="@+id/web_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello there. no flicker!"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
要将其滑出:
private void slideOut() {
LinearLayout actionBarFrame = (LinearLayout) findViewById(android.R.id.content).getParent();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) actionBarFrame.getLayoutParams();
params.setMargins(0, 0, 0, 0);
actionBarFrame.setLayoutParams(params);
TranslateAnimation ta = new TranslateAnimation(SIZE, 0, 0, 0);
ta.setDuration(DURATION);
ta.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
((FrameLayout) getWindow().getDecorView()).removeView(menuView);
menuView = null;
}
@Override public void onAnimationRepeat(Animation arg0) { }
@Override public void onAnimationStart(Animation arg0) { }
});
actionBarFrame.startAnimation(ta);
}
我上传了代码作为一个公共回购,所以你可以尝试这个项目完全像我一样
任何关于为什么会发生这种情况或如何解决它的帮助或想法都将不胜感激!所需的是将
WebView
平滑地从图片中移出并返回。谢谢 一般来说,在3.0+设备上启用硬件加速的情况下使用webview
时,问题似乎与bug有关。我还尝试使用带有WebView
的库,但遇到了同样的闪烁问题。环顾四周后,我发现了一个解决方法:
解决方法使用以下代码将WebView
的图层类型设置为软件渲染:
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
这段代码解决了我的闪烁问题,但性能较低。这里也有同样的问题@罗伯特:你找到解决这个问题的方法了吗?@jayellos这个问题有两种可能的解决方法。我将在下面添加一个答案,但这个故事的寓意是,在
WebView
上启用硬件加速可能会有所帮助(在某些平台上默认情况下不会启用),或者使用(我们当前的解决方案)。我可以确认解决方法是有效的。有人找到了允许硬件加速的解决方案吗?
webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);