【发布时间】:2014-09-17 04:34:08
【问题描述】:
我尝试在 xml 文件中设置列表项的行高。例如,我有一个 listView 和一个对应的 listAdapter,这个适配器从 xml 文件中膨胀一个视图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/ic_right"/>
<TextView
android:id="@+id/info"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="20dp"
android:textSize="16sp"
android:textColor="#f96f00"
android:layout_gravity="center"
android:lines="1"
android:ellipsize="end"
/>
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="12sp"
android:paddingRight="10dp"
/>
</LinearLayout>
但是这个60dp 没有任何效果,无论你设置了多少这个高度,膨胀的行视图都有一个固定的高度。当我调整布局内的 textview 时,行高发生了变化。为什么会发生这种情况,我如何将列表项行的高度分配给固定指标?
【问题讨论】:
-
把列表视图的代码也贴出来
-
你的线性布局高度 android:layout_height="match_parent" 请试试
-
我刚刚将您的代码粘贴到我的 Eclipse 中并设置了我自己的图像来代替您的图像,它看起来很好,占据 60dp 的高度,因此请检查您的图像大小和列表适配器的邮政编码
-
您在 textview 中将布局权重分配给 1。欲了解更多信息developer.android.com/guide/topics/ui/layout/linear.html#Weight
-
把你试过的代码放在这里。你的 xml 看起来不错