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;
	}

	

}

 
android viewflipper引导界面
 

 
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>

   

相关推荐