1

Androidの静的にwebviewの高さと幅を設定できますか?

皆さんありがとう

4

2 に答える 2

0

はい、XMLファイルでweb view.setの高さと幅を設定できますここにコードスニペットがあります( WebView android:id="@+id/webView1" android:layout_width="250dip" android:layout_height="250dip" /)

于 2012-05-24T12:21:15.367 に答える
0

それを行った後、動的なコンテンツのサイズが重要になります。便利なことを行うために 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
//=========
于 2016-07-24T21:18:45.603 に答える