A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 吴光新   /  2013-8-15 17:47  /  15364 人查看  /  206 人回复  /   1 人收藏 转载请遵从CC协议 禁止商业使用本文

阿斯顿撒大大发啊
回复 使用道具 举报
这个看看是怎么实现的
回复 使用道具 举报
public class MineListView extends ListView implements Runnable {
    private float mLastDownY = 0f;  
    private int mDistance = 0;  
    private int mStep = 0;  
    private boolean mPositive = false;  
   
  

    public MineListView (Context context, AttributeSet attrs) {  
          super(context, attrs);  
    }  
  
    public MineListView (Context context, AttributeSet attrs, int defStyle) {  
          super(context, attrs, defStyle);  
    }  
  
    public MineListView (Context context) {  
          super(context);  
    }  
  
    @Override  
    public boolean onTouchEvent(MotionEvent event) {  
         switch (event.getAction()) {  
              case MotionEvent.ACTION_DOWN: //手指按下时触发
                   if (mLastDownY == 0f && mDistance == 0) {                        
                         mLastDownY = event.getY();  
                   return true;  
              }  
              break;  
  
    case MotionEvent.ACTION_CANCEL:  
           break;

    case MotionEvent.ACTION_UP: //手指抬起之后触发
          if (mDistance != 0) {  
            
           mStep = 1;  
           mPositive = (mDistance >= 0);  
           this.post(this);         
           return true;  
        }  
        mLastDownY = 0f;  
        mDistance = 0;  
        break;  
  
    case MotionEvent.ACTION_MOVE:  //手指按下之后滑动触发
        if (mLastDownY != 0f) {               
              mDistance = (int) (mLastDownY - event.getY());  
              if ((mDistance < 0 && getFirstVisiblePosition() == 0 &&
                getChildAt(0).getTop() == 0) || (mDistance > 0 &&
                 getLastVisiblePosition() == getCount() - 1)) {  
                  //第一个位置并且是想下拉,就滑动或者最后一个位置向上拉  
                  //这个判断的作用是在非顶端的部分不会有此滚动
                  mDistance /= 2; //这里是为了减少滚动的距离
                   scrollTo(0, mDistance); //滚动
                   return true;  
               }  
        }  
        mDistance = 0;  
        break;  
        }  
        return super.onTouchEvent(event);  
    }  
  
    public void run() {  
          mDistance += mDistance > 0 ? -mStep : mStep;  
          scrollTo(0, mDistance);  
          if ((mPositive && mDistance <= 0) || (!mPositive && mDistance >= 0)) {  
                scrollTo(0, 0);  
                mDistance = 0;  
                mLastDownY = 0f;  
                return;  
           }  
          mStep += 1;  
        this.postDelayed(this, 7);
         
         
     }  
   

   
   
}  
回复 使用道具 举报
好东西 谢谢共享
回复 使用道具 举报
不错,值得一看。
回复 使用道具 举报
下载了收藏
回复 使用道具 举报
学习学习
回复 使用道具 举报
学习学习怎么实现
回复 使用道具 举报
没啥说的先顶在下!!!!!!!!!!
回复 使用道具 举报
学习一下。。。。
回复 使用道具 举报
一库一库一库一库一库
回复 使用道具 举报
很想学习学习
回复 使用道具 举报
谢谢楼主分享
回复 使用道具 举报
不错,下载来看看
回复 使用道具 举报
嗯,好像是的
回复 使用道具 举报
好东西啊  谢谢啊
回复 使用道具 举报
学习下,以后备用~~~~~~
回复 使用道具 举报
111111111111111111111111111111
回复 使用道具 举报
asdasdada23
232da1s3d

回复 使用道具 举报
反弹的时候匀速,无论拖拽的幅度大小
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马