zoukankan      html  css  js  c++  java
  • Android中监听ScrollView滑动停止和滑动到底部

    1.监听ScrollView滑动停止:

    [java] view plaincopy
     
    1. /********************监听ScrollView滑动停止*****************************/  
    2. scrollView.setOnTouchListener(new OnTouchListener() {  
    3.     private int lastY = 0;  
    4.     private int touchEventId = -9983761;  
    5.     Handler handler = new Handler() {  
    6.         @Override  
    7.         public void handleMessage(Message msg) {  
    8.             super.handleMessage(msg);  
    9.             View scroller = (View) msg.obj;  
    10.             if (msg.what == touchEventId) {  
    11.                 if (lastY == scroller.getScrollY()) {  
    12.                     handleStop(scroller);  
    13.                 } else {  
    14.                     handler.sendMessageDelayed(handler.obtainMessage(touchEventId, scroller), 5);  
    15.                     lastY = scroller.getScrollY();  
    16.                 }  
    17.             }  
    18.         }  
    19.     };  
    20.   
    21.   
    22.     public boolean onTouch(View v, MotionEvent event) {  
    23.         if (event.getAction() == MotionEvent.ACTION_UP) {  
    24.             handler.sendMessageDelayed(handler.obtainMessage(touchEventId, v), 5);  
    25.         }  
    26.         return false;  
    27.     }  
    28.   
    29.   
    30.     private void handleStop(Object view) {  
    31.         ScrollView scroller = (ScrollView) view;  
    32.         scrollY = scroller.getScrollY();  
    33.     }  
    34. });  
    35. /***********************************************************/  



    2.监听ScrollView滑动到底部:

    [java] view plaincopy
     
      1. package com.example.webviewdemo;  
      2.   
      3. import android.content.Context;  
      4. import android.util.AttributeSet;  
      5. import android.widget.ScrollView;  
      6.   
      7. public class ScrollBottomScrollView extends ScrollView {  
      8.   
      9.     private ScrollBottomListener scrollBottomListener;  
      10.   
      11.     public ScrollBottomScrollView(Context context) {  
      12.         super(context);  
      13.     }  
      14.   
      15.     public ScrollBottomScrollView(Context context, AttributeSet attrs) {  
      16.         super(context, attrs);  
      17.     }  
      18.   
      19.     public ScrollBottomScrollView(Context context, AttributeSet attrs,int defStyle) {  
      20.         super(context, attrs, defStyle);  
      21.     }  
      22.   
      23.     @Override  
      24.     protected void onScrollChanged(int l, int t, int oldl, int oldt){  
      25.         if(t + getHeight() >=  computeVerticalScrollRange()){  
      26.             //ScrollView滑动到底部了  
      27.             scrollBottomListener.scrollBottom();  
      28.         }  
      29.     }  
      30.   
      31.     public void setScrollBottomListener(ScrollBottomListener scrollBottomListener){  
      32.         this.scrollBottomListener = scrollBottomListener;  
      33.     }  
      34.   
      35.     public interface ScrollBottomListener{  
      36.         public void scrollBottom();  
      37.     }  
      38.   
      39. }  
  • 相关阅读:
    把office文档转换为html过程中的一些坑
    Win10内置应用恢复初始状态
    HTTP 错误 500.23
    关于Application.Lock和Lock(obj) 转 http://www.cnblogs.com/yeagen/archive/2012/03/01/2375610.html
    正则表达式 细节
    Python常用内置函数总结
    将Python脚本封装成exe可执行文件 转
    爬虫技能
    python之map、filter、reduce、lambda函数 转
    小细节
  • 原文地址:https://www.cnblogs.com/exmyth/p/4531765.html
Copyright © 2011-2022 走看看