user2462809
user2462809

Reputation: 1

Android Listview Items fill-parent whit weight

I got this listview:

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

In the listview i will load a linearlayout:

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

In that LinearLayout i got a weight of 1, so when the list loads it will get divided equally between all the items. Now the problem is this doesn't work, is this even possible whit weight and loading items in the listview?

Upvotes: 0

Views: 3230

Answers (1)

Nirali
Nirali

Reputation: 13825

weight property is for LinearLayout. Your parent layout should be LinearLayout. So I don't think the code that you have written is possible scenario.

Whenever you specify weight either width or height should be set to 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>

Upvotes: 1

Related Questions