Implementation of listview rounded corners

Source: Internet
Author: User

The custom control is used here to customize the listview.

Package COM. example. demo; import android. content. context; import android. util. attributeset; import android. view. motionevent; import android. widget. adapterview; import android. widget. listview;/*** rounded listview */public class listcorn extends listview {public listcorn (context) {This (context, null);} public listcorn (context, attributeset attrs) {super (context, attrs); // The rounded corner background of the entire listview this. setbackgroundresource (R. drawable. corner_list_bg);} @ 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) {// only one setselector (R. drawable. corner_list_single_item);} else {// The first setselector (R. drawable. corner_list_first_item) ;}} else if (itemnum = (getadapter (). getcount ()-1) {// The Last setselector (R. drawable. corner_list_last_item);} else {// intermediate item setselector (R. drawable. corner_list_item) ;}} break; Case motionevent. action_up: break;} return Super. onintercepttouchevent (EV );}}

Then apply it to the layout file.

 <com.example.demo.ListCorn      android:id="@+id/ydlist"      android:layout_below="@+id/edit"      android:layout_width="match_parent"      android:layout_height="wrap_content"      android:layout_alignParentBottom="true"      android:layout_centerHorizontal="true"      android:layout_margin="10dp"       android:cacheColorHint="#00000000"      android:scrollbars="none" >  </com.example.demo.ListCorn>

 

 

 

 

 

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.