缩小视图内容宽度以适合屏幕 [英] Shrink Webview Content width to fit the screen
问题描述
我试着缩小我的WebView的宽度含量降低到适合我的屏幕,所以我不必须滚动侧办法了......我试过很多code,但它仍犯规任何人有任何想法如何?
我的继承人code为止。
后览=(的WebView)findViewById(R.id.postView);
postView.setScrollBarStyle(WebView.OVER_SCROLL_NEVER);
postView.setInitialScale((INT)0.8);
WebSettings设置= postView.getSettings();
settings.setLoadWithOverviewMode(真);
settings.setUseWideViewPort(真);
settings.setDomStorageEnabled(真);
settings.setJavaScriptEnabled(真);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
那么你可以定义屏幕宽度本身的WebView的宽度,并将其添加到它的参数部分。
INT屏幕宽度= getWindowManager()
。.getDefaultDisplay()的getWidth();
postView.setLayoutParams(新TableRow.LayoutParams(
屏幕宽度/ 2,LayoutParams.MATCH_PARENT,1F));
/ *我假设你的WebView父tablerow的。您必须定义布局PARAMS相对于其父。一样,如果后览parentview是的LinearLayout那么新LinearLayout.LayoutParams()必须使用* /
这必须解决您的问题。
希望,这有助于。
修改
好了,现在我明白你的问题。但我认为你的情况,你应该让用户得到放大/缩小,这样用户将得到控制,他要查看数据。
添加此语句
postView.getSettings()setBuiltInZoomControls(真)。
Im trying to shrink the width content of my webview down to fit with my screen so i dont have to scroll side way anymore...i tried so many code but it still doesnt anyone have any idea how??
heres my code so far.
postView = (WebView) findViewById(R.id.postView);
postView.setScrollBarStyle(WebView.OVER_SCROLL_NEVER);
postView.setInitialScale((int) .8);
WebSettings settings = postView.getSettings();
settings.setLoadWithOverviewMode(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setJavaScriptEnabled(true);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
Well you can define width of webview with screenwidth itself and add it to its param section.
int screenWidth = getWindowManager()
.getDefaultDisplay().getWidth();
postView.setLayoutParams(new TableRow.LayoutParams(
screenWidth / 2, LayoutParams.MATCH_PARENT, 1f));
/*I have assumed your webview's parent is tablerow. You must define layout params with respect to its parent. like if postview parentview is linearlayout then new LinearLayout.LayoutParams() must be used*/
This must solve your problem.
Hope, this helps.
Edit
Ok, now I get your problem. But I think in your case you should allow the user to get zoom in/out , so that user will get control for data he wants to view.
Add this statement
postView.getSettings().setBuiltInZoomControls(true);
这篇关于缩小视图内容宽度以适合屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!