Remove unwanted White Space in WebView Android

后端 未结 11 2047
庸人自扰
庸人自扰 2020-11-30 02:05

I have started developing an App using WebView. Actually I am loading an Image with Webview (I like to use the built-in zoom controls of the class). I can successfully load

相关标签:
11条回答
  • 2020-11-30 02:23

    My case, top of my webview has big padding. So, set scrollbarSize="0dp". In AS 2.2.3

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    
    <WebView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/webView"
    android:scrollbarSize="0dp"
    />
    
    0 讨论(0)
  • 2020-11-30 02:24

    i don't really know which whitespace you are referring to ( maybe the image has padding or so), but usually if you have any layout issues in a WebView you would try to fix them by providing a proper (inline) css-stylesheet.

    0 讨论(0)
  • 2020-11-30 02:28

    Set the padding in your webview.xml to 0dp

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <WebView
        android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp" />
    

    0 讨论(0)
  • 2020-11-30 02:29

    I already got it .

    here my logic code, When the application open the website you must get the size of your webview then set it on height

    here my code

     ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) webpage.getLayoutParams();
            p.height = webpage.getHeight();
            Log.e(" webpage.getHeight()", String.valueOf(webpage.getHeight()));
            webpage.setLayoutParams(p);
    

    Hope you will take my code and my answer to :) works on any devices even tabs too :)

    0 讨论(0)
  • 2020-11-30 02:33

    I had this [this is my activity.xml]

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
    

    I just deleted the padding in the relativeLayout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" 
    tools:context=".MainActivity">
    

    I tried all the solutions above but they didn't go very well for me. this one worked for me.

    0 讨论(0)
提交回复
热议问题