0

我有一个列表视图,其项目包含左侧联系人的头像。在剩余的空间中,有两行文本,第一行包含人名,第二行包含电子邮件地址(或其他任何文本)。

我想对列表项的布局进行样式设置,以便:

  • 头像图像位于视图的最左侧。左侧没有填充。

  • 列表项的高度仅由两行文本的高度决定。无论图像是大还是小,图像视图都必须匹配这个高度

  • imageview的顶部或底部不能有填充。

  • imageview 必须始终是 square,即使图像本身是矩形的。在这种情况下,图像应该被“缩放”以填充整个正方形,因为它可以垂直或水平裁剪,但纵横比必须保持不变。

这是 ICS Messaging 应用程序的屏幕截图,它符合所有这些标准:

在此处输入图像描述

我已经阅读了几个涉及 的 SO 线程android:scaleType,尝试了许多scaleType,adjustViewBoundswrapContent/match_parent设置的组合,但我从来没有做对。有人可以帮忙吗?

下面是一些可以作为起点的简化 XML 布局:

<!-- The avatar -->
<ImageView
    android:id="@+id/contactImageView"
    android:layout_width="???"
    android:layout_height="???"
    android:layout_alignParentLeft="true" />

<!-- The 2-row textual layout -->
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@+id/contactImageView"
    android:orientation="vertical" >

    <!-- First row -->
    <TextView
        android:id="@+id/nameTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <!-- Second row -->
    <TextView
        android:id="@+id/emailTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

4

1 回答 1

0

如果您修复 ImageView 的宽度和高度并将 ScaleType 设置为 centerCrop,您应该拥有您想要的。

<ImageView
    android:id="@+id/contactImageView"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_alignParentLeft="true"
    android:scaleType="centerCrop" />
于 2012-12-03T20:34:35.513 回答