1

我正在尝试为我的ListView项目构建一个布局,类似于 Gmail 应用程序的标签列表,其中左侧有标签文本,右侧有计数。除了长文本外,我所拥有的大部分都有效。我的结果导致文本与计数重叠。

这就是我试图模仿的:

在此处输入图像描述

如您所见,底部标签没有包裹顶部标签所在的位置(请阅读下文了解更多详细信息)。

当两个标签都有计数时,每行的计数阵容:

在此处输入图像描述

有了我所拥有的,最后一个项目应该有 3 个显示,但它正在重叠。另外,我希望TextView每一行的“计数”与 Gmail 应用程序的排列方式相同(中心,右对齐,我猜?):

在此处输入图像描述

布局代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="1"       
>

    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:padding="10dp"
        android:gravity="left"
        android:layout_weight=".75"
    />

    <TextView 
        android:id="@+id/count"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:gravity="right|center_vertical" 
        android:padding="10dp"
        android:layout_weight=".25"
    />
</LinearLayout>

我知道当您使用时,layout_weight您应该将其设置layout_width为 0px,但是,这会导致每一行都在同一位置被截断。如果它比 count 长,我只想要文本换行TextView

我不擅长 Android 布局,我认为使用它们非常令人沮丧,所以这可能很容易。谢谢。

4

2 回答 2

1

您应该能够通过使用 aRelativeLayout而不是您的LinearLayout、使用layout_toRightOflayout_toLeftOfXML 属性来相对于彼此定位视图来防止视图重叠。

于 2012-10-29T00:01:18.913 回答
0

弄清楚了。我需要添加android:layout_toLeftOf="@+id/count"TextView上面 Ernir 回答的第一个

于 2012-11-01T01:40:45.907 回答