Android:自定义列表视图项目 - 强制在一行

时间:2012-10-29 14:02:22

标签: java android listview

我的listview有一个自定义单元格,它有TEXT NUMBER - 工作正常,但是当TEXT超过一行时,右手数字也超过一行,看起来很傻。是否有房产可以解决这个问题?

enter image description here

我的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="wrap_content"
    android:orientation="horizontal" >
    <TextView
        android:id="@+id/txtOption"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="7"
        android:paddingBottom="5dp"
        android:paddingTop="5dp"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />


    <TextView
        android:id="@+id/txtCount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:paddingBottom="5dp"
        android:paddingLeft="25dp"
        android:paddingRight="15dp"
        android:paddingTop="5dp"
        android:text="[21]"
        android:textAppearance="?android:attr/textAppearanceMedium" />


</LinearLayout>

1 个答案:

答案 0 :(得分:1)

似乎您的layout_weight视图没有被踢入。为此,我认为您缺少在android:weightSum="10"定义中定义LinearLayout。此外,您需要将android:layout_width="0dp"设置为TextView