将Android中包含网络视图的FrameLayout旋转90度



我正在尝试在android中旋转包含webview的框架布局,这是我的代码:

FrameLayout contentView = (FrameLayout) getRootView().findViewById(
                R.id.content);
FrameLayout backGround = new FrameLayout(getContext());
FrameLayout.LayoutParams bgfl = new FrameLayout.LayoutParams(
    FrameLayout.LayoutParams.FILL_PARENT,
    FrameLayout.LayoutParams.FILL_PARENT);
backGround.addView(WebView object);
contentView.addView(backGround, bgfl);
RotateAnimation r = new RotateAnimation(0f, -90f,Animation.RELATIVE_TO_SELF,0.5f, 
Animation.RELATIVE_TO_SELF,0.5f);
r.setDuration(0);
r.setFillAfter(true); 
LayoutAnimationController animController = new LayoutAnimationController(r, 0);
backGround.setLayoutAnimation(animController);

它可以旋转……但问题是,网络视图中的任何可点击区域都不会根据布局的旋转坐标系更改其坐标。此外,网络视图的滚动正在反转

关于如何解决此问题的任何建议

我也遇到过类似的问题,在动画运行时,即使"什么都没有",也能激活UI的一部分。您使用的RotateAnimation仅更新视图的视觉效果,FrameLayout的所有元素在其原始位置保持不变。

一种可能性是为FrameLayout创建一个单独的布局,该布局设置为看起来像旋转后的视图。通过实现Animation.AnimationListener并将实例化代码放入onAnimationEnd(Animation)方法中,可以在Activity中实例化此布局。

根据setDuration(int)值为0,您可能根本不关心视图是否已设置动画。在这种情况下,您可以将启动LayoutAnimation的代码替换为替换布局的代码。

最新更新