我正在尝试实现类似Facebook、Path或Google+ Android应用程序的滑动导航。可以在此处找到完整的源代码以重现此错误。
然而,在设备上将
我已将代码上传至 BitBucket 作为公共仓库,所以您可以像我一样尝试此项目。
非常感谢任何关于为什么会发生这种情况或如何修复它的帮助或想法!期望的是平稳地将
然而,在设备上将
WebView
动画化移出屏幕时,会出现闪烁,就好像设备在将其推出屏幕之前咬了一口我的WebView
一样。
这个问题在模拟器上不会出现!动画可以平稳地进行。
有趣的是,当动画的视图是WebView
时,似乎只会出现闪烁!这里是使用 TextView 作为主要内容视图的相同项目。
网页视图活动的布局:
<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 slideIn() {
LinearLayout actionBarFrame = (LinearLayout) findViewById(android.R.id.content).getParent();
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
menuView = inflater.inflate(R.layout.menu, null);
menuView.setLayoutParams(new FrameLayout.LayoutParams(SIZE, LayoutParams.MATCH_PARENT, Gravity.LEFT));
FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
decorView.addView(menuView);
decorView.bringChildToFront(actionBarFrame);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) actionBarFrame.getLayoutParams();
params.setMargins(SIZE, 0, -SIZE, 0);
actionBarFrame.setLayoutParams(params);
TranslateAnimation ta = new TranslateAnimation(-SIZE, 0, 0, 0);
ta.setDuration(DURATION);
actionBarFrame.startAnimation(ta);
}
并将其滑动回去:
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);
}
我已将代码上传至 BitBucket 作为公共仓库,所以您可以像我一样尝试此项目。
非常感谢任何关于为什么会发生这种情况或如何修复它的帮助或想法!期望的是平稳地将
WebView
动画移出屏幕并再次移回。谢谢!
WebView
上启用硬件加速可以帮助解决问题(某些平台上默认未启用),或使用此库(我们目前的解决方案)。 - Robert Karl