2

現在、以下を使用して高さと幅を設定しています。

//landsapeWebView is a WebView, and deviceHeight and deviceHeight are ints
landsapeWebView.setLayoutParams(new RelativeLayout.LayoutParams(deviceHeight, deviceWidth));

これは、一部のデバイスでは正常に機能するようですが、他のデバイスでは機能しないようです。私がたどり着いた唯一の結論は、これが高さと幅を次のように設定しているということです:

<WebView  android:layout_width="(deviceWidth)dp"
          android:layout_height="(deviceHeight)dp" />

私が欲しいのはこれです:

<WebView  android:layout_width="(deviceWidth)px"
          android:layout_height="(deviceHeight)px" />

測定単位を指定するにはどうすればよいですか?


@collusionbdbhの追加開示

    display      = getWindowManager().getDefaultDisplay();

    if(getResources().getConfiguration().orientation == 1){
        deviceWidth  = display.getWidth();
        deviceHeight = display.getHeight();
    }else{
        deviceWidth  = display.getHeight();
        deviceHeight = display.getWidth();
    }

ここに画像の説明を入力

4

2 に答える 2

2

これを試して:

DisplayMetrics metrics = this.getResources().getDisplayMetrics();
int width = metrics.widthPixels;
int height = metrics.heightPixels;
于 2012-10-11T01:18:44.030 に答える
0

オリエンテーションの問題ではないと確信していますか?

デバイスの向きに関係なく、幅は横、高さは縦です。

私はこれを試してみます:

display      = getWindowManager().getDefaultDisplay();
    deviceWidth  = display.getWidth();
    deviceHeight = display.getHeight();

高さの前に幅が必要だと確信しています:

landsapeWebView.setLayoutParams(new RelativeLayout.LayoutParams(deviceHeight, deviceWidth));

次のようにする必要があります。

landsapeWebView.setLayoutParams(new RelativeLayout.LayoutParams(deviceWidth, deviceHeight));
于 2012-10-11T01:05:15.547 に答える