Apply style to Android ListView

I want the lisview style in my application to see this image

Expected Output

I tried to develop it by applying a gradient:

code for list_item_normal:

<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <gradient android:centerColor="#E6E6E6" android:endColor="#CCCCCC" android:startColor="#FFFFFF" android:angle="270"/> <!-- <gradient android:startColor="#FF7500" android:centerColor="#FFCC00" android:endColor="#FF7500" android:angle="270"/> --> <stroke android:width="1dp" android:color="#A0000000" /> <padding android:bottom="8dp" android:left="5dp" android:right="5dp" android:top="8dp" /> <corners android:radius="5dp" /> </shape> 

code for list_item_pressed.xml:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:centerColor="#E6E6E6" android:endColor="#CCCCCC" android:startColor="#FFFFFF" android:angle="270"/> <!-- <gradient android:startColor="#FF66CFE6" android:centerColor="#FF207FB9" android:endColor="#FF0060B8" android:angle="270"/> --> <stroke android:width="2dp" android:color="#80000000" /> <padding android:bottom="8dp" android:left="5dp" android:right="5dp" android:top="8dp" /> <corners android:radius="7dp" /> </shape> 

code for list_item_pressed.xml:

 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:centerColor="#E6E6E6" android:endColor="#CCCCCC" android:startColor="#FFFFFF" android:angle="270"/> <!-- <gradient android:startColor="#FF66CFE6" android:centerColor="#FF207FB9" android:endColor="#FF0060B8" android:angle="270"/> --> <stroke android:width="2dp" android:color="#80000000" /> <padding android:bottom="8dp" android:left="5dp" android:right="5dp" android:top="8dp" /> <corners android:radius="7dp" /> </shape> 

and list_gradient.xml

 <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/list_item_pressed" /> <item android:state_focused="true" android:drawable="@drawable/list_item_selected" /> <item android:drawable="@drawable/list_item_normal" /> </selector> 

and I applied this style on a custom listitem like:

 <TextView .../> <ImageView ... /> 

and main.xml in which I have lisview:

 <ListView android:id="@+id/List" style="@style/list_item_gradient" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:clickable="true" > </ListView> 

and I get the output as shown below:

current output

Please help me by letting me know what I'm doing wrong.

Thanks Shruti

+4
source share
2 answers

Do you know about Dithering? Check it out: http://android.amberfog.com/?p=247 .

Also check out the following questions:

And yes, I would suggest creating a custom adapter for your LitsView, in which you just need to create one own xml layout file and apply the background image at a time.

+5
source

create customAdapter extends baseAdapter . create list_item.xml and set the desired settings selector selector against its background. It is he.

+1
source

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


All Articles