Android 包含文本和图像的ListView

Android 包含文本和图像的ListView,android,listview,layout,Android,Listview,Layout,我正在尝试创建一个包含文本和图像的列表视图。填充布局是可行的,但我对ImageView的layout\u height=“wrap\u content”有问题。填充列表后,列表项的高度是图像高度的两倍,图像本身上下都有大量空间。如何避免空白并将ListItem高度环绕在图像周围 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_

我正在尝试创建一个包含文本和图像的列表视图。填充布局是可行的,但我对
ImageView
layout\u height=“wrap\u content”
有问题。填充列表后,列表项的高度是图像高度的两倍,图像本身上下都有大量空间。如何避免空白并将
ListItem
高度环绕在图像周围

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/product_preview_product"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center" />

    <ImageView
        android:id="@+id/product_preview_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/product_preview_product" />
</RelativeLayout>
用这个

android:layout_width="wrap_content"
android:layout_height="wrap_content"

如果图像较大,请在此处设置适当的大小。

设置布局及其子窗口小部件的权重 android:weightSum=“1.2”


我多次遇到相同的问题并设置

android:adjustViewBounds="true"  
android:scaleType="fitCenter"
在我看来,我做到了,试一试。要修改的文档说

如果希望ImageView调整其边界以保留其可绘制视图的纵横比,请将其设置为true


发布1的屏幕截图。你目前拥有的和2.你想要实现的。你最大的图像的大小是多少?
android:adjustViewBounds=“true”
在你的ImageView和
android:scaleType=“fitCenter”
android:adjustViewBounds=“true”
成功了!我如何接受评论?XD@A.S.发布答案…您的解决方案似乎有助于操作…匹配父内容和换行内容的组合:如何在线性布局中指定相对位置?还有,如果它是相对的,你怎么能给出权重?是的,我们需要使用线性布局并分配权重和。在相对论中,我们不能给出权重
<TextView
    android:id="@+id/product_preview_product"
    android:layout_width="wrap_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_weight=".2"
    android:gravity="center" />
<ImageView
    android:id="@+id/product_preview_image"
    android:layout_width="wrap_parent"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:layout_below="@id/product_preview_product" />
android:adjustViewBounds="true"  
android:scaleType="fitCenter"