Man*_*ran 38 android space image padding android-webview
我已经开始使用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)
San*_*ndy 56
默认情况下,webview在正文中有一些边距/填充.如果要删除该填充/边距,则覆盖正文标记并添加边距,如:
<body style="margin: 0; padding: 0">
Run Code Online (Sandbox Code Playgroud)
Ben*_*Ben 21
如果您正在谈论的空白区域位于右侧,则可以将其添加到webview中.
mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
Run Code Online (Sandbox Code Playgroud)
这应该使白色空间消失,只要它位于滚动条的右侧.
Bla*_*des 18
通过Defualt HTML网页的填充和边距为10px; 你必须在你的head部分或css文件中设置:
<style type="text/css">
html, body {
width:100%;
height: 100%;
margin: 0px;
padding: 0px;
}
</style>
Run Code Online (Sandbox Code Playgroud)
这对我有用.
我的WebView中呈现的HTML内容边缘有刺激性的空白区域(尽管该内容中没有图像).起初我认为它与上面提到的CSS问题有关.但是通过使用样式表来改变HTML,BODY等的背景,它看起来越来越像在WebView周围填充.
user3241873在上面显示了如何调整WebView本身的填充,但我发现当Eclipse创建的默认Android应用程序生成布局文件(RelativeLayout"container"而不是"LinearLayout")时,它将这些属性添加到RelativeLayout:
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
Run Code Online (Sandbox Code Playgroud)
如果在res/values/dimens.xml中查找这些填充值,您将看到它们设置为16dp.当我改为0dp时,它删除了难看的空白区域:)
如果有人用WebView替换了默认的(Hello World)TextView,那么父亲RelativeLayout的填充就像家里一个令人讨厌的亲戚一样.
归档时间: |
|
查看次数: |
36246 次 |
最近记录: |