Search code examples
androidwebviewandroid-webviewandroid-xmlandroid-designer

Webview contents getting cropped from bottom [ANDROID]


In my app i a displaying a webpage in webview, using url of webpage. The url loads fine but the issue is that some content of web page is cropped from bottom. How this issue can be fixed? Any help will be appreciated. Here is my code

xml code

<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 code

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");

Solution

  • try this use scrollview

    <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>