Android development-square rounded listview

Source: Internet
Author: User

I wrote this article and was inspired by the blog post published by kiritor's column on Android UI controls to achieve the rounded Corner Effect of listview.

First look:

First, you have to write a class named cornerlistview.

 

/*** Rounded listview example ** @ Description: rounded listview example * @ filename: cornerlistview. java */public class cornerlistview extends listview {public cornerlistview (context) {super (context);} public cornerlistview (context, attributeset attrs, int defstyle) {super (context, attrs, defstyle);} public cornerlistview (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

 

<?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

 

<?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

 

<?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

 

<?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> 

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.