android--to determine how the ListView slides up and down

Source: Internet
Author: User

1Elv_music_res_fragment.setonscrolllistener (NewAbslistview.onscrolllistener () {2             Private intmlastfirstpostion = 0;3             Private intMlastfirsttop = 0;4             Private intTouchslop =Viewconfiguration.get (Getactivity ()). Getscaledtouchslop ();5 6 @Override7              Public voidOnscrollstatechanged (Abslistview view,intscrollstate) {8 9             }Ten  One @Override A              Public voidOnscroll (Abslistview Abslistview,intFirstvisibleitem,intVisibleItemCount,intTotalitemcount) { -                 intCurrenttop; -  theView Firstchildview = Abslistview.getchildat (0); -                 if(Firstchildview! =NULL) { -Currenttop = Abslistview.getchildat (0). GetTop (); -}Else { +                     //when the ListView initializes, the Onscroll method is recalled, and Getchildat (0) is still empty. -                     return; +                 } A                 //determine the last visible first position and this visible first position at                 if(Firstvisibleitem! =mlastfirstpostion) { -                     //not the same location . -                     if(Firstvisibleitem >mlastfirstpostion) { -                         //under -                         if(Rg_container_resfragment.getvisibility ()! =view.gone) { - rg_container_resfragment.setvisibility (view.gone); in                         } -}Else { to                         //on +                         if(Rg_container_resfragment.getvisibility ()! =view.visible) { - rg_container_resfragment.setvisibility (view.visible); the                         } *                     } $Mlastfirsttop =Currenttop;Panax Notoginseng}Else { -                     //It's the same place . the                     if(Math.Abs (Currenttop-mlastfirsttop) >touchslop) { +                         //avoid action execution too often or wrong touch, add touchslop judgment, the specific value can be adjusted A                         if(Currenttop >mlastfirsttop) { the                             //on +                             if(Rg_container_resfragment.getvisibility ()! =view.visible) { - rg_container_resfragment.setvisibility (view.visible); $                             } $}Else if(Currenttop <mlastfirsttop) { -                             //under -                             if(Rg_container_resfragment.getvisibility ()! =view.gone) { the rg_container_resfragment.setvisibility (view.gone); -                             }Wuyi                         } theMlastfirsttop =Currenttop; -                     } Wu                 } -Mlastfirstpostion =Firstvisibleitem; About             } $});

android--to determine how the ListView slides up and down

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.