【问题标题】:Webview contents getting cropped from bottom [ANDROID]Webview 内容从底部被裁剪 [ANDROID]
【发布时间】:2017-07-15 04:07:35
【问题描述】:

在我的应用程序中,我使用网页的 url 在 webview 中显示网页。 url 加载正常,但问题是网页的某些内容是从底部裁剪的。如何解决这个问题?任何帮助将不胜感激。 这是我的代码

xml代码

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/app_bg_color"
    >
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <include
        layout="@layout/empty_result_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>

Java 代码

String Content = "<h2>" + ItemDetail.getTitle() + "</h2>\n" + ItemDetail.getWebviewContent();
Content = Content.replaceAll("a href=\"/", "a href=\"" + ConstantFile.SERVER_ADDRESS + "/");

webview.loadDataWithBaseURL(null, Content, "text/html", "UTF-8", null);
webview.getSettings().setDefaultTextEncodingName("UTF-8");

【问题讨论】:

    标签: android webview android-webview android-xml android-designer


    【解决方案1】:

    试试这个使用滚动视图

    <ScrollView
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fillViewport="true"> 
    
      <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:tools="http://schemas.android.com/tools"
       android:id="@+id/container"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:background="@color/app_bg_color" >
        <WebView
          android:id="@+id/webview"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
    
       <include
          layout="@layout/empty_result_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent" />
       </RelativeLayout>
    
    </ScrollView>
    

    【讨论】:

    • 最欢迎@User
    【解决方案2】:

    尝试将WebView 赋予layout_weight="1"height0dp

    【讨论】:

      猜你喜欢
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-03
      • 2017-02-10
      • 2017-03-30
      • 2019-05-17
      • 1970-01-01
      相关资源
      最近更新 更多