在安卓中旋转包含WebView的FrameLayout 90 度

4
我正在尝试在Android中旋转包含WebView的FrameLayout,以下是我的代码:

我正在尝试在Android中旋转包含WebView的FrameLayout,以下是我的代码:

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);

旋转功能正常,但问题在于webview中的任何可点击区域都不会根据布局的旋转坐标系更改其坐标。此外,webview的滚动也被反转。

有什么建议可以解决这个问题吗?


也许你需要类似这里的触摸事件代码(链接:https://dev59.com/r3A75IYBdhLWcg3wJFmY)。 - dokkaebi
1个回答

0

我曾经遇到过类似的问题,即使没有任何东西,动画仍在运行时无法激活 UI 的一部分。你正在使用的 RotateAnimation 只更新视图的可视化效果,所有的 FrameLayout 元素仍然保持在它们原来的位置。

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

根据你的 setDuration(int) 值为 0,看起来你甚至不关心是否看到视图动画。在这种情况下,你可以用替换布局的代码来代替启动你的 LayoutAnimation 的代码。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接