Android列表视图项目填充 - 父级白色权重

时间:2013-06-07 08:45:23

标签: android android-layout android-listview android-linearlayout android-layout-weight

我得到了这个列表视图:

            <ListView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/listView2"
                android:divider="#CCCCCC"
                android:dividerHeight="1px"
                android:cacheColorHint="#00000000" />

在列表视图中,我将加载一个linearlayout:

        <LinearLayout
            android:layout_weight="1" 
            android:layout_height="fill_parent"
            android:layout_width="fill_parent"
            android:background="#ffffff"/>

在LinearLayout中,我的权重为1,因此当列表加载时,它将在所有项目之间平均分配。现在的问题是这不起作用,这是否可能在列表视图中加载项目的权重和加载项目?

1 个答案:

答案 0 :(得分:1)

权重属性适用于LinearLayout 您的父布局应该是LinearLayout。所以我认为您编写的代码不是可能的场景。

每当指定重量时,宽度或高度都应设置为0dp。

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="5">

<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="1" />

<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:text="2" />

<Button
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:text="3" />

</LinearLayout>