Transparent divider in a listview

前端 未结 7 1618
予麋鹿
予麋鹿 2021-01-02 13:47

I am creating a listiview programmatically. I keep a divider between listview elements. I wish to keep a transparent divider because I have a background image to be shown. I

相关标签:
7条回答
  • 2021-01-02 13:49

    In the xml file containing the list view you are using set the attribute android:divider="#00000000" on the list view. You can also set the divider height to 0dp if you wanted.

    0 讨论(0)
  • 2021-01-02 13:49

    It worked for SDK >= 15

    android:divider="@null"
    
    0 讨论(0)
  • 2021-01-02 14:01

    Try this:

    color.xml: (res > values > color.xml)

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <drawable name="transperent_color">#00000000</drawable>    
    </resources>
    

    Now,use it like:

    setListAdapter(new ArrayAdapter<String>(this,R.layout.news,news));
    ListView lv=getListView();
    lv.setDivider(this.getResources().getDrawable(R.drawable.transperent_color));
    lv.setDividerHeight(20);
    
    0 讨论(0)
  • 2021-01-02 14:02

    @kusi if you have not setContentView(R.layout.yourlayout); then you should have to declare it and then in that layout file you have to declare this ListView

    <ListView android:id="@android:id/list"
        android:layout_width="match_parent" 
        android:layout_height="match_parent"
        android:divider="#00000000"
        android:dividerHeight="20dip"
        /> 
    

    note that you must have to set id of this listview as android:id="@android:id/list" in case you have extends ListActivity in your Activity Class.

    0 讨论(0)
  • 2021-01-02 14:12

    this line brings it standardized, usable everywhere ... :)

    getListView().setDivider(this.getResources().getDrawable(android.R.color.transparent));

    if you also call -> setDividerHeight, call setDivider first.

    good luck && have fun :=)

    0 讨论(0)
  • 2021-01-02 14:13

    Add,

    android:divider="@null"
    

    in the xml for the divider. This will ensure that the absence of the divider.

    0 讨论(0)
提交回复
热议问题