android viewflipper引导界面

看了下android viewfillper + GestureDetector 做指引界面效果还不错。图片自己添加。布局很简单
package com.example.test.game;

import java.io.File;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.webkit.MimeTypeMap;
import android.widget.ImageView;
import android.widget.ViewFlipper;

import com.example.test.FileUtils;
import com.example.test.R;

public class TestActivity extends Activity {

	GestureDetector gesture;
	ViewFlipper flipper;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.test_img);
		flipper = (ViewFlipper) findViewById(R.id.flipper);
		//添加图片
		flipper.addView(getImageView(R.drawable.i20130806162515));
		flipper.addView(getImageView(R.drawable.i20130806162840));
		flipper.addView(getImageView(R.drawable.i20130806164717));
		
		gesture = new GestureDetector(this, new OnGestureListener() {
			// 用户(轻触触摸屏后)松开,由一个1个MotionEvent ACTION_UP触发
			@Override
			public boolean onSingleTapUp(MotionEvent e) {
				System.out.println("onSingleTapUp");
				return false;
			}

			// 用户轻触触摸屏,尚未松开或拖动,由一个1个MotionEvent ACTION_DOWN触发
			// 注意和onDown()的区别,强调的是没有松开或者拖动的状态
			@Override
			public void onShowPress(MotionEvent e) {
				System.out.println("onShowPress");

			}

			// 用户按下触摸屏,并拖动,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触发
			@Override
			public boolean onScroll(MotionEvent e1, MotionEvent e2,
					float distanceX, float distanceY) {
				System.out.println("onScroll");
				return false;
			}

			// 用户长按触摸屏,由多个MotionEvent ACTION_DOWN触发
			@Override
			public void onLongPress(MotionEvent e) {
				System.out.println("onLongPress");

			}

			// 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE,
			// 1个ACTION_UP触发
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2,
					float velocityX, float velocityY) {
				System.out.println("onFling");
				if (e1.getX() - e2.getX() > 120) {// 向右滑动
					flipper.setInAnimation(AnimationUtils.loadAnimation(TestActivity.this,
							R.anim.push_left_in));
					flipper.setOutAnimation(AnimationUtils.loadAnimation(TestActivity.this,
							R.anim.push_left_out));
					//当前是不是最后一个 可以进行滑
					if(flipper.getCurrentView().getId() != R.drawable.i20130806164717)
					{
						flipper.showNext();
					}
				} else if (e2.getX() - e1.getX() > 120) {// 向左滑动
					/*flipper.setInAnimation(AnimationUtils.loadAnimation(TestActivity.this,
							R.anim.push_right_in));
					flipper.setOutAnimation(AnimationUtils.loadAnimation(TestActivity.this,
							R.anim.push_right_out));
					flipper.showPrevious();*/

				}
				return false;
			}

			// 用户轻触触摸屏,由1个MotionEvent ACTION_DOWN触发
			@Override
			public boolean onDown(MotionEvent e) {
				System.out.println("onDown");
				return false;
			}
		});
		gesture.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
			// 短快的点击算一次单击
			@Override
			public boolean onSingleTapConfirmed(MotionEvent e) {
				System.out.println("onSingleTapConfirmed");
				return false;
			}

			// 双击时产生一次
			@Override
			public boolean onDoubleTapEvent(MotionEvent e) {
				System.out.println("onDoubleTapEvent");
				return false;
			}

			// 双击时产生两次
			@Override
			public boolean onDoubleTap(MotionEvent e) {
				System.out.println("onDoubleTap");
				return false;
			}
		});

		
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return gesture.onTouchEvent(event);
	}

	private View getImageView(int id) {
		ImageView imgView = new ImageView(this);
		imgView.setId(id);
		imgView.setImageResource(id);
		return imgView;
	}

	

}

 

 

 

 

 

 

 
push_right_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:fromXDelta="-100%p" android:toXDelta="0"        android:duration="500" />    <alpha android:fromAlpha="0.1" android:toAlpha="1.0"        android:duration="500"/></set> 


 push_right_out.xml

 

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android">    <translate android:fromXDelta="0" android:toXDelta="100%p"        android:duration="500" />    <alpha android:fromAlpha="1.0" android:toAlpha="0.1"        android:duration="500"/></set> 

   

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值