Android中包含webview的FrameLayout旋转90度

发布于 2024-12-29 08:22:12 字数 844 浏览 4 评论 0原文

我正在尝试旋转包含 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);

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

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

I am trying to rotate the framelayout containing the webview in android, here is my code :

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

It's rotating ok...but the problem is that any clickable area in the webview is not changing it's coordinates according to the rotated coordinate system of the layout.
Also the scroll of the webview is getting reversed

Any suggestion on how to fix this problem

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白况 2025-01-05 08:22:12

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

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

基于您的 setDuration(int) 值为 0,看起来您甚至可能根本不关心查看动画视图。在这种情况下,您只需将启动 LayoutAnimation 的代码替换为替换布局的代码即可。

I have had similar problems with being able to activate part of a UI while an animation was running even though there is "nothing" there. The RotateAnimation you are using only updates the visuals of the view, all of the FrameLayouts elements remain intact in their original locations.

One possibility is to create a separate layout for your FrameLayout that is set up to look like the view post-rotation. This layout can be instantiated in your Activity by Implementing Animation.AnimationListener and putting the instantiation code in the onAnimationEnd(Animation) method.

Baased on your setDuration(int) value of 0, it looks like you may not even care about seeing the view animated at all. In this case you could just replace the code that starts your LayoutAnimation with the code that replaces the layout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文