我有一個FrameLayout裏,含有各種疊加ImageViews:爲什麼我的FrameLayout有0高度?
<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渲染的確切像素高度和寬度?
你可以試試'getMeasuredHeight()'? – 2013-01-25 06:54:27
我認爲你的對話框在你讀取它的高度時沒有測量過。 – Leonidos