android - Jelly Bean 和 Froyo 的 ImageView match_parent 不同

标签 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 一样填充其父对象。非常感谢。

最佳答案

我最近才遇到同样的现象。在查看 Android 源代码并将 View 子类化(例如查看 FrameLayout 将传递给其子项的值)之后,很明显这是一个错误。

完整口味请看这里descriptionworkaround .

元注释:感谢 StackOverflow 审阅者投票赞成将我的原始答案转换为评论,然后反对将此问题标记为重复。现在这就是你得到的。 ;)

关于android - Jelly Bean 和 Froyo 的 ImageView match_parent 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16103950/

相关文章:

Android:如果 ArrayAdapter 通过函数,则将 TextView 日期设置为相同

android - Android 中 3G 的部分唤醒锁

sockets - 蓝牙 Secureaccept() 失败、Nexus 7、Android 4.2.2

android - 更改 Jelly Bean Android 中的振动设置

android - Android 2.2 有多可靠

android - 为替代键创建自定义弹出键盘

java - Android内存泄漏将匿名类实现与特定于线程的局部变量一起使用

java - 使用 GPS 捕捉速度

android - Android 2.2 + ViewPager和Fragments实现TabHost使用教程

安卓;如何在一个 Activity 中初始化状态,然后进行另一项刷新?