开发者

Android ListView Default Divider Styles / Attributes

开发者 https://www.devze.com 2023-02-16 18:01 出处:网络
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 replica开发者_如何学JAVAte the edit contact within the

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 replica开发者_如何学JAVAte 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.


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


The source of Magician Knowledge must be https://developer.android.com/reference/android/R.attr.html

public static final int listDivider:

The drawable for the list divider. Must be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name".

So all I have to do type in that site search bar - "drawable for the list divider" or just "divider"

0

精彩评论

暂无评论...
验证码 换一张
取 消