2016-11-13 235 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

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