Phil Phil - 2 months ago 12
Android Question

Child objects not distributing in a LinearLayout where the Layout is bound to a ListView

I have a LinearLayout with three child components, I cannot get them to distribute evenly though, I've tried everything I've read so far, the layout is called as part of a binding to a ListView , all of the children are placed to the left of its' respective ListItem, regardless of what I do :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/runnerName"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
style="@style/RunnerListRunnerName"
android:layout_weight="1"
android:padding="10dp"
/>
<TextView
android:id="@+id/runnerOdds"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:gravity="center"
style="@style/RunnerListRunnerName"
android:layout_weight="1"
android:padding="10dp"
/>

<TextView
android:id="@+id/runnerDutchStake"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
style="@style/RunnerListRunnerName"
android:layout_weight="1"
android:padding="10dp"
/>




I have also tried WeightSum=3 int the LinearLayout but again it makes no impact to the child distribution :
Actual output

Answer

In this case, I eventually found the answer. I agree that I did not provide enough information because the issue was in the parent ListView Item where this view is called as a ListItem.

The parent ListView Element had the Layout_width="wrap_content". I changed it to match_parent :

   <ListView
            android:layout_width="match_parent"
            android:layout_height="330dp"
            android:id="@+id/dutch_runner_list_view"
            style="@style/ListViewStyle"
            android:clickable="true" />

I found this interesting because it at least shows inherited style and heirarchy that was not immediately obvious.