Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView divider not visible

A ListActivity uses an extension of BaseAdapter and the following layout:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation="vertical"     
        android:background="@color/application_background_color">

<ListView android:id="@android:id/list" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:drawSelectorOnTop="false"
    android:divider="@drawable/divider"
    android:dividerHeight="2dip" android:clickable="true"
    android:choiceMode="singleChoice"    
    android:cacheColorHint="@color/application_background_color">
</ListView>

   </LinearLayout>

It inflates the following layout for the rows:

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

    <TextView android:id="@+id/Row" 
        android:layout_width="fill_parent" android:layout_height="50dip"
        android:textSize="20dip" android:textColor="#000000"
        android:layout_margin="8dip"
        android:gravity="center_vertical"></TextView>

    </LinearLayout>   

The drawable/divider.xml looks like this at the moment, but I've tried all different kinds:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="line">
      <stroke android:color="#FF000000">
      </stroke>
    </shape>    

If I read the drawable from an image it works. Why doesn't it work when I define the drawable as a .xml file?

Update:
The code is following the same pattern as the EfficientAdapter in the Android Developer examples:
http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html

like image 450
Vanja Avatar asked Jul 19 '11 13:07

Vanja


1 Answers

Code below works for me:

list layout:

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/list"
    android:cacheColorHint="@android:color/transparent"
    android:background="@android:color/transparent"
    android:textFilterEnabled="false"
    style="@style/ListDivider"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</ListView>

styles.xml

<resources>
    <style name="ListDivider">
        <item name="android:divider">@drawable/my_shape</item>
        <item name="android:dividerHeight">5dp</item>
    </style>
</resources>

my_shape:

    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <padding
            android:top="2dp"
            android:left="2dp"
            android:right="2dp"
            android:bottom="2dp" />
        <corners
            android:radius="5dp" />
        <solid
            android:color="@android:color/white" />
    </shape>
like image 165
pawelzieba Avatar answered Nov 08 '22 11:11

pawelzieba