package com.leaf.android;
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 leaf
*
*/
public class Main 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.img1));
flipper.addView(addTextView(R.drawable.img2));
flipper.addView(addTextView(R.drawable.img3));
flipper.addView(addTextView(R.drawable.img4));
flipper.addView(addTextView(R.drawable.img5));
}
private View addTextView(int id) {
ImageView iv = new ImageView(this);
iv.setImageResource(id);
return iv;
}
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 boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return this.detector.onTouchEvent(event);
}
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android_slideScreen.rar (36个子文件)
android_slideScreen
bin
classes.dex 4KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
android_slideScreen.apk 47KB
classes
com
leaf
android
R$layout.class 388B
R$id.class 384B
R$drawable.class 541B
R$attr.class 334B
R.class 561B
Main.class 3KB
R$string.class 421B
R$anim.class 502B
resources.ap_ 42KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
img1.jpg 6KB
ic_launcher.png 4KB
img2.jpg 4KB
img4.jpg 4KB
img5.jpg 7KB
img3.jpg 8KB
values
strings.xml 191B
drawable-mdpi
ic_launcher.png 3KB
anim
push_right_out.xml 347B
push_left_in.xml 347B
push_right_in.xml 348B
push_left_out.xml 348B
layout
main.xml 421B
assets
gen
com
leaf
android
R.java 1KB
proguard.cfg 1KB
.settings
org.eclipse.jdt.core.prefs 177B
src
com
leaf
android
Main.java 2KB
.project 855B
.classpath 364B
project.properties 361B
AndroidManifest.xml 726B
共 36 条
- 1
lifugui2007
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页