can we set webview height and width in static for android?
开发者_StackOverflow中文版Thanks all
yes you can set height and width for web view.set in XML file Here's code snippet ( WebView android:id="@+id/webView1" android:layout_width="250dip" android:layout_height="250dip" /)
AFTER you done that, the dynamic content size becomes important: You need will need the width and height of the WebView CONTENTS, after you loaded your HTML to do uselful things. YES you do, but there is no getContentWidth method (only a view port value), AND the getContentHeight() is inaccurate !
Answer: sub-class 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
//=========
精彩评论