【问题标题】:Rotating 90 degrees the FrameLayout containing webview in Android在Android中将包含webview的FrameLayout旋转90度
【发布时间】:2012-01-25 07:52:33
【问题描述】:

我正在尝试在 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 中的任何可点击区域都不会根据布局的旋转坐标系更改其坐标。 webview的滚动也被反转了

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

【问题讨论】:

  • 也许你需要像触摸事件代码here这样的东西。

标签: android view webview android-framelayout rotation


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 2011-03-22
    • 2019-07-29
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 2015-03-22
    相关资源
    最近更新 更多