【问题标题】:Android: CustomListAdapter columns not aligning properlyAndroid:CustomListAdapter 列未正确对齐
【发布时间】:2016-11-13 02:27:43
【问题描述】:

我有一个显示项目列表的页面。列表中的每一行都有三列,由于某种原因,列表中的项目没有正确对齐。 以下是我的代码:

自定义适配器:

  <TextView
    android:id="@+id/tvCategoryName"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name"
    android:layout_weight="0.90"
    android:textAlignment="textStart"/>

  <TextView
    android:id="@+id/tvWeight"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Weight"
    android:layout_weight="0.05"
    android:textAlignment="center"/>

  <TextView
    android:id="@+id/tvAverage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Average"
    android:layout_weight="0.05"
    android:textAlignment="center"/>
</LinearLayout>

以下是其显示方式的屏幕截图:

我希望Categories、Weight 和 Average 的所有三列都以带有 centered 文本对齐的格式显示在一个漂亮的表格中。

【问题讨论】:

    标签: android xml listadapter


    【解决方案1】:

    更新:将layout_width="0dp" 设置为您所有的TextView。否则 layout_weight 将无法正常工作。对于垂直方向的父布局集layout_height="0"

    也许android:layout_weight="0.05" 太小了,尝试使用更大的值,例如 tvWeight 和 tvAverage 为 0.2,tvCategoryName 为 0.6。

    【讨论】:

    • 当“类别名称”太长或太短时仍然不起作用
    • 是的,如果你使用layout_weight,你应该将layout_width设置为0dp
    猜你喜欢
    • 1970-01-01
    • 2016-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-03
    • 1970-01-01
    相关资源
    最近更新 更多