Android手势识别ViewFlipper触摸动画
最近项目中用到了ViewFlipper这个类,感觉效果真的很炫,今天自己也试着做了下,确实还不错。
首先在layout下定义viewflipper.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/viewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/b" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/c" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/d" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/f" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/g" />
</ViewFlipper>
</LinearLayout>
<?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/viewFlipper1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/b" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/c" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/d" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/f" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/g" />
</ViewFlipper>
</LinearLayout> ViewFlipper中包含了5张图片 用来手势切换。
public class ViewFlipperActivity extends Activity implements OnTouchListener, android.view.GestureDetector.OnGestureListener {
private ViewFlipper flipper;
GestureDetector mGestureDetector;
private int mCurrentLayoutState;
private static final int FLING_MIN_DISTANCE = 80;
private static final int FLING_MIN_VELOCITY = 150; <
补充:移动开发 , Android ,