我有一个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