2016-11-13 67 views
0

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

自定义适配器:

<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> 

下面是它如何显示的截图: enter image description here

我想CategoriesWeightAverage所有三列是以与centered文本对齐的格式显示在一个漂亮的表格中。

回答

1

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

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

+0

当“类别名称”太长或太短时,仍不起作用 –

+0

是的,如果您使用的是layout_weight,则应该将layout_width设置为0dp –

+0

工作正常!非常感谢你 :) –