40-line key code for Android custom Wheelview

Source: Internet
Author: User

// 给ListView设置一个滑动监听器,就可以把它变成WheelViewlistView.setOnScrollListener(new AbsListView.OnScrollListener() {    /* 实现代码如下所示 */});
@Override Public void onscrollstatechanged(Abslistview view,intScrollstate) {//When slide is stopped    if(scrollstate = = AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {View Firstvisibleview = View.getchildat (0);intHeight = firstvisibleview.getheight ();/** * Top is the relative distance, in pixels, between the top of the Firstvisibleview and the parent.         * Android's Axis origin is in the upper left corner of the screen, and the higher the Y value, the smaller. * Since Firstvisibleview is always partially invisible, the value range of top is: (-height, 0] */        inttop = Firstvisibleview.gettop ();intVisibleheight = top + height;if(Visibleheight <= (height >>1)) {//If the Firstvisibleview visible height is less than or equal to half, slide up until invisibleView.scrollby (0, Visibleheight + (ListView) view. Getdividerheight ()); }Else{//If the Firstvisibleview visible height is greater than half, slide until fully visibleView.scrolllistby (0, top); }//Call Scrollby (), the onscroll () is raised}}@Override Public void onscroll(Abslistview view,intFirstvisibleitem,intVisibleItemCount,intTotalitemcount) {intNewmiddleposition = Firstvisibleitem + ((VisibleItemCount-1) >>1);if(mmiddleposition! = newmiddleposition)        {mmiddleposition = newmiddleposition;        Baseadapter adapter = ((Baseadapter) view.getadapter ()); Adapter.notifydatasetchanged ();///You can then invoke the custom listener that listens for mmiddleposition changes}}

40-line key code for Android custom Wheelview

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.