2016-11-13 13 views
0

アイテムのリストを表示するページがあります。リストの各行には3つの列があり、何らかの理由でリストにある項目が正しく整列していません。以下 は私のコードです: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> 

それが表示されますかのスクリーンショットです:私はCategoriesWeight、およびAverageすべての3つの列になりたい enter image description here

centeredテキストアライメントの形式のような素敵な表で表示されます。

答えて

1

UPDATED:すべてTextViewsにlayout_width="0dp"を設定してください。そうしないと、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

に設定する必要があります。どうもありがとうございました :) –

関連する問題