【问题标题】:ANDROID : Webview doesn't take full widthANDROID:Webview 不占用全宽
【发布时间】:2014-11-25 16:50:37
【问题描述】:

如下所示,我有一个带有 Webview 和 Imageview 的布局。 webview 的权重必须为 0.8(宽度的 80%),而 Imageview 的权重应为 0.2(宽度的 20%)。这应该可以完美地工作,但是 webview 不占用整个宽度,它只占用宽度的一半。在三星标签上甚至更少......

我通过 stackoverflow 和互联网搜索了各种解决方案。大多数人设置你必须setLoadWithOverviewMode,它加载完全缩放的webview。这必须与 setUseWideViewPort 结合使用,强制它采用 webview 的尺寸。

我已经玩了一天了,如果有人可以提供一些帮助,将不胜感激:)

这是 HTML:

<html> 
 <meta name="viewport" content="width=device-width", initial-scale=40></meta>
    <body style='background-color: transparent; color: Grey; font-family: HelveticaNeue-Light; font-size: 10pt; width: 258px; word-wrap: break-word;'>
     <div align='left'>When changing... 
       <span style='background-color: transparent; color: #a8c916; font-family: HelveticaNeue-Light; font-size: 10pt; word-wrap: break-word;'>%d punten</span> 
       <span style='background-color: transparent; color: Grey; font-family: HelveticaNeue-Light; font-size: 10pt; word-wrap: break-word;'>%@</span>
     </div>
</body>

Java:

vh.textTagline.setInitialScale(40);
vh.textTagline.getSettings().setLoadWithOverviewMode(true);
vh.textTagline.getSettings().setUseWideViewPort(true);

XML:

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <WebView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/textTagline"
            android:layout_weight="0.8"/>
    <ImageView
        android:id="@+id/arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="17dp"
        android:paddingRight="10dp"
        android:layout_weight="0.2"/>
</LinearLayout>

【问题讨论】:

    标签: android html webview width


    【解决方案1】:

    为此,您需要对 xml 进行以下更改:

    <LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <WebView
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:id="@+id/textTagline"
            android:layout_weight="8"/>
    <ImageView
        android:id="@+id/arrow"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingTop="17dp"
        android:paddingRight="10dp"
        android:layout_weight="2"/>
    </LinearLayout>
    

    layout_weight 的宽度应为 0dp。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 2021-03-07
      • 2021-06-08
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多