ImageView match_parent与Jelly Bean和Froyo不同

时间:2013-04-19 11:49:47

标签: android android-4.2-jelly-bean android-2.2-froyo

我有一个简单的布局,并在Jelly Bean和Froyo之间产生了差异。在Jelly Bean上,我ImageView按其高度匹配其父(FrameLayout}。但在Froyo上却不是。请看一下布局结构:

<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>

所以我对Jelly Bean的看法(正如预期的那样):

enter image description here

以下是我对Froyo的看法:

enter image description here

请告知如何让ImageView填充其父级,就像Jelly Bean一样。非常感谢你。

3 个答案:

答案 0 :(得分:1)

我最近才发现这种现象。在查看Android源代码并查看子类视图以查看FrameLayout将传递给其子代的值时,很明显这是一个错误。

请在此处查看完整风格的descriptionworkaround

Meta说明:感谢StackOverflow评论员投票 将我的原始答案转换为评论,然后反对将此问题标记为重复。现在,这就是你得到的。 ;)

答案 1 :(得分:0)

FragmentLayout的{​​{1}}设置为layout_height

您的XML代码应如下所示

match_parent

答案 2 :(得分:0)

为什么不将profile_data_background_im Drawable作为@+id/ll LinearLayout的背景?无论如何,奇怪的布局组合。