Search code examples
androidlistviewandroid-linearlayoutdivider

Android ListView Default Divider Styles / Attributes


I have a LinearLayout view that I am trying to add a divider to so that it looks exactly the same as the default ListView control. I am trying to replicate the edit contact within the default Android (Nexus S 2.3.3) Contacts app and I believe a LinearLayout would be best for performance.

I am using the code to replicate the divider as shown below:

    <View
    android:id="@+id/Separator"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/dividerHeight"
    android:background="?android:attr/divider"/>

How can I access the default divider color or drawable and also the divider height? I would like this to match the ListViews I have setup, so using the Android system attributes would be best I think. The above code crashes as shown below so I assume I can't access those attributes or am going about this incorrectly.

03-13 22:59:38.851: ERROR/AndroidRuntime(3575): Caused by: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_height attribute.

Solution

  • This is how it's done in Android source code

    <View android:id="@+id/Separator"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="?android:attr/listDivider" />