我们可以为android设置静态的webview高度和宽度吗?
谢谢大家
是的,您可以在 XML 文件中设置 web view.set 的高度和宽度 这是代码片段( WebView android:id="@+id/webView1" android:layout_width="250dip" android:layout_height="250dip" /)
完成之后,动态内容大小变得很重要:在加载 HTML后,您需要 WebView CONTENTS的宽度和高度来做有用的事情。是的,但是没有 getContentWidth 方法(只有一个视口值),并且 getContentHeight() 不准确!
答:子类WebView:
/*
Jon Goodwin
*/
package com.example.html2pdf;//your package
import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebView;
class CustomWebView extends WebView
{
public int rawContentWidth = 0; //unneeded
public int rawContentHeight = 0; //unneeded
Context mContext = null; //unneeded
public CustomWebView(Context context) //unused constructor
{
super(context);
mContext = this.getContext();
}
public CustomWebView(Context context, AttributeSet attrs) //inflate constructor
{
super(context,attrs);
mContext = context;
}
public int getContentWidth()
{
int ret = super.computeHorizontalScrollRange();//working after load of page
rawContentWidth = ret;
return ret;
}
public int getContentHeight()
{
int ret = super.computeVerticalScrollRange(); //working after load of page
rawContentHeight = ret;
return ret;
}
//=========
}//class
//=========