【问题标题】:Problems with alignment of listview item列表视图项的对齐问题
【发布时间】:2023-03-31 22:25:02
【问题描述】:

我在 listview 的每一行中的各个字段的对齐方面存在问题。 有谁知道如何去 b 下 b , c 下 c 等..

谢谢!!

因为不能发截图,所以我试着做一张图片

AAAAAAA BBBBBB CCCCCC DDDDDD(这是我的头衔)
aaa bbb ccc ddd(这是我的列表视图项)

如何对齐?

【问题讨论】:

  • tiikoni.com/tis/upload上发布代码并分享屏幕截图并在此处提供链接
  • 您的要求听起来像是网格视图,而不是列表视图。

标签: android listview alignment


【解决方案1】:

我建议您将表格用于此类事情。 您可以为 ListView 中的 每一 行定义一个布局。 此行将有 4 个宽度相同的部分,并且在列表视图的同一行和不同行中应该彼此相等。

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    android:weightSum="4" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" >

        <TextView
            android:id="@+id/AAAAAAA"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center" />

        <TextView
            android:id="@+id/BBBBBBBB"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center" />

        <TextView
            android:id="@+id/CCCCCCCC"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center" />

        <TextView
            android:id="@+id/DDDDDDDD"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center" />

    </TableRow>

</TableLayout>

你可以在那里设置你的风格和任何你想要的......

我希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    • 2014-12-14
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    相关资源
    最近更新 更多