简体   繁体   English

在屏幕宽度的50%的RelativeLayout中加载WebView时出现问题

[英]Problems loading a WebView in a RelativeLayout with the 50% of the width of the screen

I have a relative layout ( A ) with fill parent width, and inside it, I have another relativelayout ( B ) with 50% of the size of the screen (376px). 我有一个具有填充父级宽度的相对布局( A ),在它里面,我还有另一个相对布局( B ),占屏幕大小(376px)的50%。

Inside RL B I have a webview, that is displaying a website. RL B内部,我有一个Web视图,它正在显示一个网站。 The size of the view is the 50% of the screen, but the website is being displayed at fullsize, it means I can only see the half part of the website, and the other half part is not being displayed. 视图的大小是屏幕的50%,但是网站以全尺寸显示,这意味着我只能看到网站的一半,而另一半则没有显示。

I want to fit the website to the view width, so I must view the 100% of the website, in a view that haves the 50% of the width of the screen 我想使网站适合视图宽度,因此我必须在屏幕宽度的50%的视图中查看网站的100%

I tried using this: 我尝试使用此:

WebView webView = new WebView(activity);

        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true); 

        webView.setVisibility(View.VISIBLE);
        webView.setEnabled(true);

        webView.loadUrl(URL);   

But it doesn't works, I only see the 50% of the width of the website, and not the full website. 但这是行不通的,我只看到网站宽度的50%,而不是整个网站的宽度。

What is wrong in the code? 代码有什么问题? Why is not working .setLoadWithOverviewMode ? 为什么.setLoadWithOverviewMode

I think you want to fix the website content into the webview properly while loading. 我认为您希望在加载时将网站内容正确地固定到webview中。 You can enable pinch in and pinch out using following code wv.getSettings().setSupportZoom(true); 您可以使用以下代码wv.getSettings().setSupportZoom(true);启用wv.getSettings().setSupportZoom(true);和缩小功能wv.getSettings().setSupportZoom(true); . This allows the user can to zoom in and out. 这使用户可以放大和缩小。 You can set the scale for webview also while loading the webpage using following code: 您还可以在加载网页时使用以下代码设置网页视图的比例尺:

WebView browser = (WebView) findViewById(R.id.webview);
browser.getSettings().setLoadWithOverviewMode(true);
browser.getSettings().setUseWideViewPort(true);

For more info you can see Set zoom for Webview 有关更多信息,请参见为Webview设置缩放

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM