1

イメージビューに設定されたときのイメージの新しいサイズを知りたいです。

私はこれを試しました:

System.out.println("Imagesize 1 w:" + imageView.getDrawable().getIntrinsicWidth()+" h "+imageView.getDrawable().getIntrinsicHeight());
System.out.println("Imagesize 2  w:" +loadedImage.getWidth()+ " h " +loadedImage.getHeight());

imageViewのxml1:

android:layout_width="fill_parent"
android:layout_height="fill_parent"

私はこの結果を持っています

Imagesize 1 w:400 h 577
Imagesize 2 w:400 h 577

imageViewのxml2:

android:layout_width="wrap_content"
android:layout_height="wrap_content"

同じ結果:

Imagesize 1 w:400 h 577
Imagesize 2 w:400 h 577

明らかに、xml1 と xml2 の場合、私の画像は同じサイズで画面に表示されません。getWidth または getHeight は画像の実際のサイズだと思いますが、画面に表示される画像のサイズが欲しいです。

何か案は?

更新 1:

loadedImage が画像のビットマップであることを忘れていました

更新 2:

xml。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="1dip" >

<ImageView
    android:id="@+id/image"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:adjustViewBounds="true"
    android:contentDescription="@string/descr_image"
    android:layout_alignParentBottom="true" />

<ProgressBar
    android:id="@+id/loading"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:visibility="gone" />

<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
/>


</RelativeLayout>
4

1 に答える 1

1

作成された後に画面オブジェクトのサイズを取得するには、次のようにビュー オブザーバーを使用する必要があります。

ViewTreeObserver viewTreeObserver = YOURLAYOUT.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      public void onGlobalLayout() {
         YOURLAYOUT.getViewTreeObserver().removeGlobalOnLayoutListener(this);
         //do some things
         //YOURLAYOUT.getWidth() should give a correct answer
      }
});
}
于 2012-12-22T00:06:07.960 に答える