2016-09-22 57 views
-1

我有一个带有三个子组件的LinearLayout,虽然我不能让它们均匀分布,但我尝试了迄今为止阅读过的所有内容,布局被称为绑定到ListView的一部分,所有的儿童被安置到其各自的列表项的左侧,无论我做什么:子对象不分布在布局绑定到ListView的LinearLayout中

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

我也曾尝试WeightSum = 3 int LinearLayout,但它不会影响子分布: Actual output

+0

我猜你没有在'Adapter'中正确地扩充布局。也就是说,你不会在'inflate()'调用中传递父'ListView'。 –

+0

没有理由的投票?那么这很有帮助 – Phil

+0

好吧,显然我不能说为什么别人会让你失望,但你实际上没有提供足够的信息。这种布局本身将按预期工作。我指出这个问题可能出现在你的'Adapter'中,但你没有发布。 –

回答

0

在这种情况下,我最终找到了答案。我同意我没有提供足够的信息,因为问题出现在父视图的ListView项中,该视图被称为ListItem。

父级ListView元素具有Layout_width =“wrap_content”。我改成了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" /> 

我发现这很有趣,因为它至少表明继承的风格和层次结构,这是不是很明显。