的WebView方向变化问题 [英] WebView Orientation change issue

查看:365
本文介绍了的WebView方向变化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面我有在那里我有一个线性布局重力为中心,使儿童中心aligned.I希望通过编程添加网页视图和装载在后援问题YouTube视频的布局是的WebView高度和宽度是WRAP_CONTENT ,wrap_content.So在纵向模式下的WebView正常工作,并在中心对齐但是当改变方向为横向网络角度的FILL_PARENT和水平覆盖屏幕,这样的内容不看中心。
这里是

I have a layout below where i have a linear layout with gravity as center to make the child center aligned.I want to add a webview programatically and loading the youtube video in it.The issue is the webview's height and width is wrap_content,wrap_content.So in portrait mode webview works fine and aligns at center but when the change the orientation to landscape web view becomes fill_parent and covers the screen horizontally so the content doesn't look at center. here is the layout file

活动code

下面是它显示的结果在纵向模式下这是很好的形象。
线性布局是绿色的颜色和网页流量是蓝色

Below are the image which shows result in portrait mode which is fine. Linear layout is in green color and webview is in blue color

和这里当u旋转设备为横向模式,其中的WebView蓝色将延伸自己明智填满整个屏幕宽度。

and here is when u rotate the device to landscape mode where webview in blue will stretch itself to fill the entire screen width wise.

我想web视图放置中心在横向模式下也同样是在纵向模式?请帮我理解这一点任何修复?

I want the webview to be placed center in landscape mode also likewise it is in portrait mode?Please help me understanding this and any fix?

推荐答案

如果你的WebView加载视频,因此aligment在WebView中是HTML的任务。总结影片,在&LT; D​​IV&GT; ,并添加适当的样式(在 CSS 文件或<$ C $在标签C>风格属性):

If you load video in WebView, so aligment in the WebView is html task. Wrap your video in the <div> and add appropriate style (in the css file or as style attribute in the tag):

<div style="margin:0 auto;width:500px;">
    //your video object is placed here
</div>

除了可以播放在VideoView的视频,但这是技术将是一个有点困难。简单地说,你要添加的FrameLayout web视图上面,让那里的VideoView应通过html文件放在COORDS和应用的LayoutParams与COORDS了VideoView。如果取向将被改变,VideoView应刷新与新COORDS。如果你感兴趣,我可以分享更多的细节。

As well you can play a video in the VideoView but this is technique will be a little more difficult. Briefly, you have to add a FrameLayout above the WebView, get the coords where the VideoView should be placed through the the html file and apply LayoutParams with coords for VideoView. If orientation will be changed, VideoView should be refreshed with the new coords. If you interested in this, i can share more details.

这篇关于的WebView方向变化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆