小编Man*_*ran的帖子

在WebView Android中删除不需要的空格

我已经开始使用WebView开发应用程序了.实际上我正在使用Webview加载图像(我喜欢使用该类的内置缩放控件).我可以成功加载图像,但我可以看到一些恼人的白色空间.我找不到删除它的方法.我的图片尺寸为750*1000.我在下面附上了我的代码.

webview.xml

<?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" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

ImageViewer.java

package com.android.test;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class ImageViewer extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.webview);

        String loadUrl = "file:///android_res/drawable/splash_001.jpg";

        WebView image = (WebView) findViewById(R.id.webView);
        image.clearView();
        image.clearCache(true);
        image.getSettings().setBuiltInZoomControls(true);
        image.getSettings().setSupportZoom(true);
        image.getSettings().setLoadWithOverviewMode(true);
        image.getSettings().setUseWideViewPort(true);
        image.loadUrl(loadUrl);
    }

}
Run Code Online (Sandbox Code Playgroud)

android space image padding android-webview

38
推荐指数
5
解决办法
4万
查看次数

标签 统计

android ×1

android-webview ×1

image ×1

padding ×1

space ×1