我在 XML 中为列表项创建相对布局以用于 ListView 中的一系列项目时遇到问题。我已经尝试了几个小时,并且正在撕扯我的头发,试图让它看起来像我想要的那样,但无法让所有东西都出现在正确的位置,而不是重叠或错位。我可以获取第一张图像和接下来的两个文本视图,但无法获取最后一个文本视图和图像视图。
我附上了一个线框风格的图像,展示了我正在尝试的外观,想知道是否有人可以帮助我?
- 右边的ImageView是一个行全高的设置图标,周围有填充?
- 两个 TextView 占据了大部分宽度。地址文本视图的文本可能很长,因此如果空间不足,可能需要被截断,或者理想情况下缩小字体大小?
- 下一个 TextView 将仅包含最多 5 个字符的小字符串。
- 最后一个 ImageView 是一个小箭头,表示可以单击该列表项以获取更多信息。它需要如图所示居中。
- 我希望图标、最后一个文本视图和最后一个图像始终位于列表中的相同位置/对齐方式。
如果有人可以提供一些帮助,我将非常感激。
干杯,伙计们
对于任何感兴趣的人,我设法让这个工作。我知道寻找问题的答案是多么痛苦,而且它从未完全解决。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/Icon"
android:layout_margin="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true" />
<TextView
android:id="@+id/topLine"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:lines="1"
android:layout_toRightOf="@+id/Icon"
android:layout_toLeftOf="@+id/distance"
android:textColor="@color/blacktext"
android:textSize="20dip"
android:text="Name" />
<TextView
android:id="@+id/bottomLine"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:lines="1"
android:layout_toRightOf="@+id/Icon"
android:layout_below="@+id/topLine"
android:layout_toLeftOf="@+id/distance"
android:textColor="@color/blacktext"
android:textSize="15dip"
android:text="Address" />
<TextView
android:id="@+id/distance"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/arrow"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:lines="1"
android:textColor="@color/blacktext"
android:textSize="12dip"
android:text="100m" />
<ImageView
android:id="@+id/arrow"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="5dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:src="@drawable/redarrow"/>
</RelativeLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)