我的布局很简单,并且碰到了Jelly Bean和Froyo之间的区别。在Jelly Bean上,我已ImageView
按高度匹配其父级(FrameLayout
)。但事实并非如此。请看一下布局结构:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/fl"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/profile_data_background_im"
android:scaleType="fitXY"/>
<LinearLayout
android:id="@+id/ll"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test text"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
所以我在果冻豆上有什么(和预期的一样):
这是我对Froyo的看法:
请建议如何使用
ImageView
来填充其父级,就像Jelly Bean一样。非常感谢你。 最佳答案
我只是最近才遇到过这种现象。在查看了Android源代码并将View子类化(例如查看FrameLayout
会传递给其子级的值)之后,很明显这是一个错误。
有关完整的description和workaround的信息,请参见此处。
注释:谢谢StackOverflow审稿人投票赞成将我的原始答案转换为评论,然后反对将此问题标记为重复。现在,这就是您要得到的。 ;)