Android Development Square Fillet ListView code sharing _android

Source: Internet
Author: User
Tags gety

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.

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.