WebView height = wrap_content with changing font s

2019-01-26 13:11发布

I have webview with layout_height = "wrap_content". If I increase default font size, then webview height increases too. But if I decrease default font size, then webview height doesn't decrease. So there is empty space on the bottom remaining.

I've tried following trick:

articleContent.getSettings().setDefaultFontSize(fontSize);
RelativeLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.BELOW, subtitleTextView.getId());
articleContent.setLayoutParams(layoutParams);

But it didn't help. I know there is the way to fix it by recreating WebView with a code when I changing default font size, but in my situation I can not do like that. I need to keep webview, because there are some views bellow it, and I can not recreate them too.

7条回答
神经病院院长
2楼-- · 2019-01-26 13:43

try this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     android:orientation="vertical" >
<WebView 
    android:id="@+id/webview1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent" />

 </LinearLayout>
查看更多
登录 后发表回答