关于Android软件欢迎界面滑屏的设计

//WelcomeActivity.java 文件
package viv.junowin;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.LayoutInflater;
import android.view.View;
import android.view.GestureDetector.OnGestureListener;
import android.view.animation.AnimationUtils;
import android.view.MotionEvent;
import android.widget.ViewFlipper;
public class WelcomeActivity extends Activity implements OnGestureListener {
// 实现拖动类效果属性声明
private ViewFlipper flipper;
private GestureDetector detector;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 注册一个用于手势识别的类
detector = new GestureDetector(this);
flipper = (ViewFlipper) this.findViewById(R.id.Viewflipper);
flipper.addView(addView(R.layout.welc_1));
flipper.addView(addView(R.layout.welc_2));
flipper.addView(addView(R.layout.welc_3));
}
private View addView(int layout) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(layout, null);
return view;
}
public boolean onTouchEvent(MotionEvent event) {
return this.detector.onTouchEvent(event);
}
// 用户轻触触摸屏,由1个MotionEvent ACTION_DOWN触发
public boolean onDown(MotionEvent arg0) {
// TODO Auto-generated method stub
//Toast.makeText(this, "onDown", Toast.LENGTH_SHORT).show();
return false;
}
// 用户按下触摸屏、快速移动后松开,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE, 1个ACTION_UP触发
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// 参数解释:
// e1:第1个ACTION_DOWN MotionEvent
// e2:最后一个ACTION_MOVE MotionEvent
// velocityX:X轴上的移动速度,像素/秒
// velocityY:Y轴上的移动速度,像素/秒
// 触发条件 :
// X轴的坐标位移大于FLING_MIN_DISTANCE,且移动速度大于FLING_MIN_VELOCITY个像素/秒
if (e1.getX() - e2.getX() > 120) {
// Fling left
//Toast.makeText(this, "Fling Left", Toast.LENGTH_SHORT).show();
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) {
// Fling right
//Toast.makeText(this, "Fling Right", Toast.LENGTH_SHORT).show();
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;
}
// 用户长按触摸屏,由多个MotionEvent ACTION_DOWN触发
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
// 用户按下触摸屏,并拖动,由1个MotionEvent ACTION_DOWN, 多个ACTION_MOVE触发
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
// 用户轻触触摸屏,尚未松开或拖动,由一个1个MotionEvent ACTION_DOWN触发
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
// 用户(轻触触摸屏后)松开,由一个1个MotionEvent ACTION_UP触发
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
//push_left_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_left_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>
//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>
//drawable-hdpi 下有背景图片的资源文件
//main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="@+id/Viewflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</ViewFlipper>
</LinearLayout>
//welc_1.xml.........
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg1"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="欢迎使用!"
android:textSize="25dp" />
</LinearLayout>

浙公网安备 33010602011771号