Android 自动调整ImageView(除了TextView)和父级高度的大小,同时保持纵横比不变

Android 自动调整ImageView(除了TextView)和父级高度的大小,同时保持纵横比不变,android,android-layout,imageview,aspect-ratio,Android,Android Layout,Imageview,Aspect Ratio,我正在努力解决一个新手问题 我的布局定义如下:(它用作listview项) 我想要实现的是: 要根据最高子级调整大小的父级布局高度。在这种情况下,如果TextView高于ImageView,ImageView纵横比应保持不变,最大宽度为可能,如果ImageView i高于TextView,则宽度应为最大,并且父级应具有高度作为ImageView 这实际上是我在JB4.3上运行的应用程序的屏幕截图。看起来和预期的一样。但是在ICS4.0.3,4.0.4上看起来是这样的 我看不出ImageV

我正在努力解决一个新手问题

我的布局定义如下:(它用作listview项)


我想要实现的是: 要根据最高子级调整大小的父级布局高度。在这种情况下,如果TextView高于ImageView,ImageView纵横比应保持不变,最大宽度为可能,如果ImageView i高于TextView,则宽度应为最大,并且父级应具有高度作为ImageView

这实际上是我在JB4.3上运行的应用程序的屏幕截图。看起来和预期的一样。但是在ICS4.0.3,4.0.4上看起来是这样的

我看不出ImageVIew没有填补空白的任何原因


帮助..

请为scaleType尝试值fitXY。顺便说一句,除非我遗漏了什么,否则我认为你的线性布局毫无用处。还有,就像你说的。。如果在垂直布局中设置了重量,则高度应为0dp,在水平线性布局中,宽度应设置为0dp以获得更好的性能。

在水平线性布局中使用
weight
时,您总是将
width
设置为
0dp
我已经设置了0dp宽度值,但对ICSLinearLayout1的任何更改都不包含一个以上的TextView,但这些项被设置为GONE visibility(我希望客户端请求在某个时候将它们设置为VISIBLE状态),但它们的存在与我描述的问题无关。现在,我已经将scaleYpe更改为fitXY,正如我所期望的,图像被拉伸(宽度被填充),但高度很小(如第二个屏幕截图)。我把宽度改为0dp。虽然它在JB上工作,但在IC上不工作。ICS上的adjustViewBound出现问题,请将
ImageView
的高度设置为
match\u parent
。它现在没有缩放,因为它尝试使用的最大高度是图像的高度。
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/articleSmallImageView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:adjustViewBounds="true"
        android:scaleType="fitStart" />

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:layout_weight="2"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/newsIntroText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:text="TextView"
            android:textColor="@color/black" />

    </LinearLayout>
</LinearLayout>