さまざまなオーバーレイされたImageViewを含むFrameLayoutがあります。
<FrameLayout
android:id="@+id/australia_frame"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/australia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/map_australia"
/>
<ImageView
android:id="@+id/nsw"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/map_nsw"
android:visibility="invisible"
/>
<ImageView
android:id="@+id/victoria"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/map_victoria"
android:visibility="invisible"
/>
...etc...
</FrameLayout>
私のコードでは、FrameLayoutをレンダリングしようとしています。
final Dialog dialog = new Dialog((Context) parent);
dialog.setContentView(R.layout.dialog_region);
FrameLayout fl = (FrameLayout) dialog.findViewById(R.id.australia_frame);
final int height = fl.getHeight();
Validate.isTrue(height > 0);
私のコードは次のようにクラッシュします:
java.lang.IllegalArgumentException: The validated expression is false
at org.apache.commons.lang3.Validate.isTrue(Validate.java:180)
クラッシュしている行はValidate.isTrue(height > 0);
です。
FrameLayoutに高さがないのはなぜですか?FrameLayoutがレンダリングしている正確なピクセルの高さと幅を取得する方法はありますか?