First look at the effect of the picture:
First, you have to write a class we named Cornerlistview
[Java]
Copy Code code as follows:
/**
* Rounded Corner ListView sample
* @Description: Rounded corner ListView Sample
* @FileName: Cornerlistview.java
*/
public class Cornerlistview extends ListView {
Public Cornerlistview {
Super (context);
}
Public Cornerlistview (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
Public Cornerlistview (context context, AttributeSet Attrs) {
Super (context, attrs);
}
@Override
public boolean onintercepttouchevent (Motionevent ev) {
Switch (ev.getaction ()) {
Case Motionevent.action_down:
int x = (int) ev.getx ();
int y = (int) ev.gety ();
int itemnum = pointtoposition (x, y);
if (Itemnum = = adapterview.invalid_position)
Break
else{
if (itemnum==0) {
if (itemnum== (Getadapter (). GetCount ()-1)) {
Setselector (R.drawable.<span style= "COLOR: #ff0000" >app_list_corner_round</SPAN>);
}else{
Setselector (R.drawable.<span style= "COLOR: #ff0000" >app_list_corner_round_top</SPAN>);
}
}else if (itemnum== (Getadapter (). GetCount ()-1))
Setselector (R.drawable.<span style= "COLOR: #ff0000" >app_list_corner_round_bottom</SPAN>);
else{
Setselector (R.drawable.<span style= "COLOR: #ff0000" >app_list_corner_shape</SPAN>);
}
}
Break
Case MOTIONEVENT.ACTION_UP:
Break
}
return super.onintercepttouchevent (EV);
}
}
/**
* Rounded Corner ListView sample
* @Description: Rounded corner ListView Sample
* @FileName: Cornerlistview.java
*/
public class Cornerlistview extends ListView {
Public Cornerlistview {
Super (context);
}
Public Cornerlistview (context context, AttributeSet attrs, int defstyle) {
Super (context, attrs, Defstyle);
}
Public Cornerlistview (context context, AttributeSet Attrs) {
Super (context, attrs);
}
@Override
public boolean onintercepttouchevent (Motionevent ev) {
Switch (ev.getaction ()) {
Case Motionevent.action_down:
int x = (int) ev.getx ();
int y = (int) ev.gety ();
int itemnum = pointtoposition (x, y);
if (Itemnum = = adapterview.invalid_position)
Break
else{
if (itemnum==0) {
if (itemnum== (Getadapter (). GetCount ()-1)) {
Setselector (R.drawable.app_list_corner_round);
}else{
Setselector (R.drawable.app_list_corner_round_top);
}
}else if (itemnum== (Getadapter (). GetCount ()-1))
Setselector (R.drawable.app_list_corner_round_bottom);
else{
Setselector (R.drawable.app_list_corner_shape);
}
}
Break
Case MOTIONEVENT.ACTION_UP:
Break
}
return super.onintercepttouchevent (EV);
}
}
Among them, App_list_corner_round
[HTML]
Copy Code code as follows:
<span style= "COLOR: #333333" ><?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:topleftradius= "6dip"
Android:toprightradius= "6dip"
Android:bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
</shape> </SPAN>
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:topleftradius= "6dip"
Android:toprightradius= "6dip"
Android:bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
</shape>
App_list_corner_round_top
[HTML]
Copy Code code as follows:
<span style= "COLOR: #333333" ><?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:topleftradius= "6dip"
android:toprightradius= "6dip"/>
</shape> </SPAN>
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:topleftradius= "6dip"
android:toprightradius= "6dip"/>
</shape>
App_list_corner_round_bottom
[HTML]
Copy Code code as follows:
<span style= "COLOR: #333333" ><?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
</shape> </SPAN>
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
<corners android:bottomleftradius= "6dip"
android:bottomrightradius= "6dip"/>
</shape>
App_list_corner_shape
[HTML]
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
</shape>
<?xml version= "1.0" encoding= "Utf-8"?>
<shape xmlns:android= "Http://schemas.android.com/apk/res/android" >
<gradient android:startcolor= "#BFEEFF"
Android:endcolor= "#40B9FF"
android:angle= "270"/>
</shape>
Once you've written it, you can call it directly like ListView in your code.