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