package com.android.flip;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ViewFlipper;
/**
* Android实现左右滑动效果
*
* @author Administrator
*
*/
public class MainActivity extends Activity implements OnGestureListener {
private ViewFlipper flipper;
private GestureDetector detector;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
detector = new GestureDetector(this);
flipper = (ViewFlipper) this.findViewById(R.id.ViewFlipper1);
flipper.addView(addTextView(R.drawable.one));
flipper.addView(addTextView(R.drawable.two));
flipper.addView(addTextView(R.drawable.three));
flipper.addView(addTextView(R.drawable.four));
flipper.addView(addTextView(R.drawable.five));
}
private View addTextView(int id) {
ImageView iv = new ImageView(this);
iv.setImageResource(id);
return iv;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
@Override
public boolean onDown(MotionEvent e) {
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > 120) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_left_out));
this.flipper.showNext();
return true;
} else if (e1.getX() - e2.getX() < -120) {
this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_in));
this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
R.anim.push_right_out));
this.flipper.showPrevious();
return true;
}
return false;
}
@Override
public void onLongPress(MotionEvent e) {
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
return false;
}
@Override
public void onShowPress(MotionEvent e) {
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}
}
金枝玉叶9
- 粉丝: 206
- 资源: 7637
最新资源
- 3b116应急物资供应管理系统_springboot+vue.zip
- 3b119灾情救援系统_springboot+vue0.zip
- 3b117应急知识学习系统_springboot+vue.zip
- 产品展示交易平台源代码.zip
- Win64OpenSSL 工具
- 3b118员工日志管理信息系统_springboot+vue.zip
- 车票网上预订系统源代码.zip
- 宠物系统源代码.zip
- 大创管理系统源代码.zip
- 3b120在线仓库_springboot+vue0.zip
- 3b121在线考试系统_springboot+vue.zip
- 大学生就业招聘系统源代码.zip
- 电影评论网站系统源代码.zip
- 房产销售系统源代码.zip
- 蓝桥杯赛场资源包里的LCD驱动和芯片资源包V1.2、V1.3、V1.4 其余资料自行下载,全部资料太大了上传不了
- 3b122智能排课系统_springboot+vue.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈