someone new someone new - 26 days ago 5
Android Question

Android: CustomListAdapter columns not aligning properly

I have a page that displays a list of items. Each row in the list has three columns and for some reason, the items int he list are not aligning properly.
Below is my code:

Custom Adapter:


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


Below is a screenshot of how it gets displayed:
enter image description here

I want
Categories
,
Weight
, and
Average
all three columns to be displayed in a nice table like format with
centered
text-alignment.

Answer

UPDATED: Set layout_width="0dp" to all yours TextViews. Otherwise the layout_weight will not work properly. For vertical oriented parent layout set layout_height="0"

And maybe the android:layout_weight="0.05" is too little, try to use some bigger value, like 0.2 for tvWeight and tvAverage and 0.6 for tvCategoryName.