我有一个列表视图,其项目包含左侧联系人的头像。在剩余的空间中,有两行文本,第一行包含人名,第二行包含电子邮件地址(或其他任何文本)。
我想对列表项的布局进行样式设置,以便:
头像图像位于视图的最左侧。左侧没有填充。
列表项的高度仅由两行文本的高度决定。无论图像是大还是小,图像视图都必须匹配这个高度。
imageview的顶部或底部不能有填充。
imageview 必须始终是 square,即使图像本身是矩形的。在这种情况下,图像应该被“缩放”以填充整个正方形,因为它可以垂直或水平裁剪,但纵横比必须保持不变。
这是 ICS Messaging 应用程序的屏幕截图,它符合所有这些标准:
我已经阅读了几个涉及 的 SO 线程android:scaleType
,尝试了许多scaleType
,adjustViewBounds
和wrapContent
/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>