package com.hll.ViewFlipperTest;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnDoubleTapListener;
import android.view.GestureDetector.OnGestureListener;
import android.view.View.OnTouchListener;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ViewFlipper;
public class ViewFlipperTest extends Activity implements OnTouchListener,
OnGestureListener, OnDoubleTapListener {
private ViewFlipper mFlipper;
GestureDetector mGestureDetector;
private int mCurrentLayoutState;
private static final int FLING_MIN_DISTANCE = 100;
private static final int FLING_MIN_VELOCITY = 200;
TextView counttv;
Button buttonNext1 = null,
buttonNext2 = null;
ListView lv1 = null,
lv2 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findView();
setListener();
}
public void findView() {
mFlipper = (ViewFlipper) findViewById(R.id.details);
// 注册一个用于手势识别的类
mGestureDetector = new GestureDetector(this);
mCurrentLayoutState = 0;
// 允许长按住ViewFlipper,这样才能识别拖动等手势
mFlipper.setLongClickable(true);
counttv = (TextView) findViewById(R.id.counttv);
buttonNext1 = (Button) findViewById(R.id.Button_next1);
buttonNext2 = (Button) findViewById(R.id.Button_next2);
lv1 = (ListView) findViewById(R.id.list1);
// lv2 = (ListView) findViewById(R.id.list2);
lv1.setAdapter(new HgroupAdapter(this,null,0));
}
public void setListener() {
// 给mFlipper设置一个listener
mFlipper.setOnTouchListener(this);
lv1.setOnTouchListener(this);
counttv.setText("9");
buttonNext1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mFlipper.showNext();
counttv.setText("7");
}
});
buttonNext2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
mFlipper.showNext();
counttv.setText("8");
}
});
}
/**
* 此方法在本例中未用到,可以指定跳转到某个页面
*/
public void switchLayoutStateTo(int switchTo) {
while (mCurrentLayoutState != switchTo) {
if (mCurrentLayoutState > switchTo) {
mCurrentLayoutState--;
mFlipper.setInAnimation(inFromLeftAnimation());
mFlipper.setOutAnimation(outToRightAnimation());
mFlipper.showPrevious();
} else {
mCurrentLayoutState++;
mFlipper.setInAnimation(inFromRightAnimation());
mFlipper.setOutAnimation(outToLeftAnimation());
mFlipper.showNext();
}
}
;
}
/** * 定义从右侧进入的动画效果 * @return */
protected Animation inFromRightAnimation() {
Animation inFromRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromRight.setDuration(500);
inFromRight.setInterpolator(new AccelerateInterpolator());
return inFromRight;
}
/** * 定义从左侧退出的动画效果 * @return */
protected Animation outToLeftAnimation() {
Animation outtoLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoLeft.setDuration(500);
outtoLeft.setInterpolator(new AccelerateInterpolator());
return outtoLeft;
}
/** * 定义从左侧进入的动画效果 * @return */
protected Animation inFromLeftAnimation() {
Animation inFromLeft = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, -1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(500);
inFromLeft.setInterpolator(new AccelerateInterpolator());
return inFromLeft;
}
/** * 定义从右侧退出时的动画效果 * @return */
protected Animation outToRightAnimation() {
Animation outtoRight = new TranslateAnimation(
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, +1.0f,
Animation.RELATIVE_TO_PARENT, 0.0f,
Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(500);
outtoRight.setInterpolator(new AccelerateInterpolator());
return outtoRight;
}
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
/*
* * 用户按下触摸屏、快速移动后松开即触发这个事件 * e1:第1个ACTION_DOWN MotionEvent *
* e2:最后一个ACTION_MOVE MotionEvent * velocityX:X轴上的移动速度,像素/秒 *
* velocityY:Y轴上的移动速度,像素/秒 * 触发条件 : *
* X轴的坐标位移大于FLING_MIN_DISTANCE,且移动速度大于FLING_MIN_VELOCITY个像素/秒
*/
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// 当像左侧滑动的时候 //设置View进入屏幕时候使用的动画
mFlipper.setInAnimation(inFromRightAnimation());
// 设置View退出屏幕时候使用的动画
mFlipper.setOutAnimation(outToLeftAnimation());
mFlipper.showNext();
} else if (e2.getX() - e1.getX() > FLING_MIN_DISTANCE
&& Math.abs(velocityX) > FLING_MIN_VELOCITY) {
// 当像右侧滑动的时候
mFlipper.setInAnimation(inFromLeftAnimation());
mFlipper.setOutAnimation(outToRightAnimation());
mFlipper.showPrevious();
}
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public boolean onTouch(View v, MotionEvent event) {
// 一定要将触屏事件交给手势识别类去处理(自己处理会很麻烦的)
return mGestureDetector.onTouchEvent(event);
}
public boolean onDoubleTap(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Android应用源码之手势滑动源码(适合新手).zip项目安卓应用源码下载
共116个文件
png:52个
class:30个
xml:12个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 12 浏览量
2022-03-08
19:22:36
上传
评论
收藏 1.61MB ZIP 举报
温馨提示
Android应用源码之手势滑动源码(适合新手).zip项目安卓应用源码下载Android应用源码之手势滑动源码(适合新手).zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码之手势滑动源码(适合新手).zip项目安卓应用源码下载 (116个子文件)
resources.ap_ 196KB
resources.ap_ 196KB
ViewFlipperTest.apk 204KB
ViewFlipperTest.apk 204KB
ViewFlipperTest.class 6KB
ViewFlipperTest.class 6KB
ViewFlipperTest2.class 3KB
ViewFlipperTest2.class 3KB
HgroupAdapter.class 2KB
HgroupAdapter.class 2KB
ViewFlipperTest$1.class 1KB
ViewFlipperTest$2.class 1KB
ViewFlipperTest$2.class 1KB
ViewFlipperTest$1.class 1KB
ViewFlipperTest2$2.class 984B
ViewFlipperTest2$1.class 984B
ViewFlipperTest2$1.class 984B
ViewFlipperTest2$2.class 984B
R$drawable.class 749B
R$drawable.class 749B
R$id.class 618B
R$id.class 618B
R.class 617B
R.class 617B
HgroupAdapter$ViewHolder.class 500B
HgroupAdapter$ViewHolder.class 500B
R$anim.class 448B
R$anim.class 448B
R$string.class 442B
R$layout.class 442B
R$string.class 442B
R$layout.class 442B
R$attr.class 355B
R$attr.class 355B
.classpath 288B
.classpath 288B
classes.dex 11KB
classes.dex 11KB
ViewFlipperTest.java 6KB
ViewFlipperTest.java 6KB
ViewFlipperTest2.java 3KB
ViewFlipperTest2.java 3KB
HgroupAdapter.java 2KB
HgroupAdapter.java 2KB
R.java 2KB
R.java 2KB
bookshelf.png 105KB
bookshelf.png 105KB
bookshelf.png 104KB
bookshelf.png 104KB
bg.png 59KB
bg.png 59KB
bg.png 59KB
bg.png 59KB
mail3.png 4KB
mail3.png 4KB
mail3.png 4KB
mail3.png 4KB
icon.png 4KB
icon.png 4KB
handler_icon.png 4KB
handler_icon.png 4KB
handler_icon.png 4KB
handler_icon.png 4KB
icon.png 4KB
icon.png 4KB
btn_iphone.png 3KB
btn_iphone.png 3KB
btn_iphone.png 3KB
btn_iphone.png 3KB
chat4.png 3KB
chat4.png 3KB
chat4.png 3KB
chat4.png 3KB
icon.png 3KB
icon.png 3KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
icon.png 2KB
btn_ready_normal.png 1KB
btn_ready_normal.png 1KB
btn_ready_normal.png 1KB
btn_ready_normal.png 1KB
a4.9.png 1006B
a4.9.png 1006B
a4.9.png 814B
a4.9.png 814B
divider_horizontal_bright.png 415B
divider_horizontal_bright.png 415B
divider_horizontal_bright.png 415B
divider_horizontal_bright.png 415B
title_bg.png 410B
title_bg.png 410B
title_bg.png 410B
title_bg.png 410B
org.eclipse.jdt.core.prefs 629B
org.eclipse.jdt.core.prefs 629B
共 116 条
- 1
- 2
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功