Transparent delimiter in list

I am creating a listiview programmatically. I keep the separator between list items. I want to keep the transparent separator because I have a background image to display. I tried the following code that does not work. Request for help

setListAdapter(new ArrayAdapter<String>(this,R.layout.news,news)); ListView lv=getListView(); ColorDrawable sage= new ColorDrawable(this.getResources().getColor(Color.TRANSPARENT)); lv.setDivider(sage); lv.setDividerHeight(20); 
+6
source share
6 answers

Try the following:

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); 
+29
source

@kusi if you did not installContentView (R.layout.yourlayout); then you should declare it, and then in this layout file you need 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 need to set the id of this list as android: id = "@android: id / list" if you increase ListActivity in your activity class.

+19
source

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

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

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

luck and & have fun: =)

+10
source

Plz use the following code for transparent separator in list view. This will happen for the following code.

 lv.setDivider(null); 
+6
source

In the xml file containing the list view you are using, set the android: divider = "# 00000000" attribute as a list. You can also set the height of the separator to 0dp if you want.

+4
source

It worked for SDK> = 15

 android:divider="@null" 
+1
source

Source: https://habr.com/ru/post/901685/


All Articles