Code sharing of square rounded corner listview in android Development

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.