多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > 互聯(lián)網(wǎng) > ListView反彈

ListView反彈

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-10-14 19:31:04 閱讀次數(shù):2978次
package com.rebound.myscroll;


import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.LinearInterpolator;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.ListView;


/**
 * listView反彈
 * 
 */
public class ListViewFantan extends LinearLayout {


private float y_down;


public ListViewFantan(Context context, AttributeSet attrs) {
super(context, attrs);
}


@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
float y2 = ev.getY();
float y_move = 0;
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
y_down = y2;
break;
case MotionEvent.ACTION_MOVE:
y_move = y2 - y_down;
break;
case MotionEvent.ACTION_UP:
break;


default:
break;
}
// listview到頂了,頂部反彈
if (listView != null && y_move > 20
&& listView.getFirstVisiblePosition() == 0) {
View childAt = listView.getChildAt(0);
if (childAt != null && childAt.getTop() == 0) {
move_top = true;
move_bottom = false;
return true;// 自己處理
}
}
// listview到底了,底部反彈
if (listView != null) {
// listView.
View childAt = listView.getChildAt(listView.getChildCount() - 1);
if (childAt != null) {
int top = childAt.getTop();
int bottom = childAt.getBottom();
int height = getHeight();
System.out.println("bottom:" + bottom + "height:" + height);
if (bottom <= height && y_move < -20) {
move_bottom = true;
move_top = false;
// 到底了
return true;// 自己處理
}
}
}
return false;
}


/**
* 向上移動(dòng)(頂部反彈)
*/
private boolean move_top;
/**
* 向下移動(dòng)(底部反彈)
*/
private boolean move_bottom;


@Override
public boolean onTouchEvent(MotionEvent ev) {
float y2 = ev.getY();
float y_move = 0;
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
y_down = y2;
//System.out.println("down:" + y_down);
break;
case MotionEvent.ACTION_MOVE:
y_move = y2 - y_down;
//System.out.println("move:" + y_move);
if (move_top) {
//頂部反彈
this.setPadding(0, (int) y_move, 0, 0);
//System.out.println("padding_top:" + y_move);
} else if (move_bottom) {
//底部反彈
int abs = (int)Math.abs(y_move);
// System.out.println("padding_bottom:"+abs);
this.setPadding(0, 0, 0,abs );
MarginLayoutParams layoutParams = (MarginLayoutParams) listView
.getLayoutParams();
layoutParams.topMargin = (int) y_move;
listView.setLayoutParams(layoutParams);
}
invalidate();
break;
case MotionEvent.ACTION_UP:
//System.out.println("up/////////");
if (move_top) {

TranslateAnimation translateAnimation = new  TranslateAnimation( 0, 0,y_move, 0);
translateAnimation.setDuration(200);
translateAnimation.setFillAfter(true);
translateAnimation.setInterpolator(new  LinearInterpolator());
//translateAnimation.start();
translateAnimation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
ListViewFantan.this.setPadding(0, 0, 0, 0);
}
});
listView.startAnimation(translateAnimation);
} else if (move_bottom) {

TranslateAnimation translateAnimation = new  TranslateAnimation( 0, 0,y_move, 0);
translateAnimation.setDuration(200);
translateAnimation.setFillAfter(true);
translateAnimation.setInterpolator(new  LinearInterpolator());
//translateAnimation.start();
translateAnimation.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationEnd(Animation animation) {
ListViewFantan.this.setPadding(0, 0, 0, 0);
MarginLayoutParams layoutParams = (MarginLayoutParams) listView
.getLayoutParams();
layoutParams.topMargin = 0;
listView.setLayoutParams(layoutParams);
}
});
listView.startAnimation(translateAnimation);
}
invalidate();
move_top = false;
move_bottom = false;
break;


default:
break;
}
return super.onTouchEvent(ev);
}


private ListView listView;


@Override
protected void onFinishInflate() {
super.onFinishInflate();
View childAt = getChildAt(0);
if (childAt instanceof ListView) {
listView = (ListView) childAt;
}
}


}


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 老司机精品视频午夜免费视频 | 成人欧美视频在线看免费 | 欧美在线看片 | 永久免费视频网站在线观看 | 亚洲人成77777在线播放网站不卡 | 欧美一级视频免费观看 | 日本欧美一区二区三区视频 | 亚洲欧美另类精品久久久 | 一区二区三区四区欧美 | 可以看黄的网址 | 韩国成人毛片aaa黄 韩国春性xxxx猛交 | 国产香蕉在线精彩视频 | 日本国产中文字幕 | 精品视频在线观看一区二区三区 | 私啪影院 | 国产在线视频资源 | 亚洲黄区 | 自拍偷拍另类 | 国产精品国产三级国产爱网 | 一级毛片在线免费视频 | xxx暴力xxx| 国产午夜亚洲精品不卡 | 亚洲 春色 另类小说 | 在线观看操 | 奇奇影院理论片在线观看 | 亚洲毛片在线观看 | 亚洲国产天堂久久九九九 | 久久福利网站 | 一区二区三区精品国产欧美 | 欧美人与动人物姣配xxxx | 欧美视频一级 | 日本人成免费大片 | 亚洲五月婷婷 | 亚洲日本中文 | 精品国产亚洲人成在线 | 国产亚洲欧美久久精品 | 久久久高清 | 一本久到久久亚洲综合 | 日本高新1区2区3区 日本国产亚洲 | 国产日韩欧美在线一区二区三区 | 国产欧美日韩一区二区三区视频 |