First look:
First, you have to write a class named CornerListView.
[Java]
Copy codeThe Code is as follows :/**
* Rounded ListView example
* @ Description: rounded ListView example
* @ FileName: CornerListView. java
*/
Public class CornerListView extends ListView {
Public CornerListView (Context context ){
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 ListView example
* @ Description: rounded ListView example
* @ FileName: CornerListView. java
*/
Public class CornerListView extends ListView {
Public CornerListView (Context context ){
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 );
}
}
App_list_corner_round
[Html]
Copy codeThe Code is 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" type = "parmname" text = "parmname"/>
<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" type = "parmname" text = "parmname"/>
<Corners android: topLeftRadius = "6dip"
Android: topRightRadius = "6dip"
Android: bottomLeftRadius = "6dip"
Android: bottomRightRadius = "6dip"/>
</Shape>
App_list_corner_round_top
[Html]
Copy codeThe Code is 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" type = "parmname" text = "parmname"/>
<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" type = "parmname" text = "parmname"/>
<Corners android: topLeftRadius = "6dip"
Android: topRightRadius = "6dip"/>
</Shape>
App_list_corner_round_bottom
[Html]
Copy codeThe Code is 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" type = "parmname" text = "parmname"/>
<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" type = "parmname" text = "parmname"/>
<Corners android: bottomLeftRadius = "6dip"
Android: bottomRightRadius = "6dip"/>
</Shape>
App_list_corner_shape
[Html]Copy codeThe Code is 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" type = "parmname" text = "parmname"/>
</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" type = "parmname" text = "parmname"/>
</Shape>
After writing it, You can directly call it in your code like listview.