在布局文件中entering.xml

<ViewFlipper        android:id="@+id/entering_vf"        android:layout_width="fill_parent"        android:layout_height="350dip"        android:flipInterval="1000"        android:persistentDrawingCache="animation"        android:visibility="invisible" >        <include            android:id="@+id/entering_carpart01"            layout="@layout/entering_carpart01" />        <include            android:id="@+id/entering_carpart02"            layout="@layout/entering_carpart02" />    </ViewFlipper>

布局文件entering_carpart01

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="390dip"        android:gravity="center_horizontal"        android:orientation="vertical" >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginBottom="40dip"            android:layout_marginTop="20dip"            android:gravity="center_horizontal"            android:orientation="horizontal" >            <FrameLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_gravity="center" >                <ImageView                    android:id="@+id/entering_iv_carpre"                    android:layout_width="293dip"                    android:layout_height="151dip"                    android:layout_marginLeft="100dip"                    android:background="@drawable/car_01" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPreWindow"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="240dip"                    android:layout_marginTop="8dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarLight"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="160dip"                    android:layout_marginTop="50dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPre"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="243dip"                    android:layout_marginTop="30dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPlate"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="243dip"                    android:layout_marginTop="83dip" />                <ImageView                    android:id="@+id/entering_iv_carbehind"                    android:layout_width="253dip"                    android:layout_height="162dip"                    android:layout_marginLeft="500dip"                    android:background="@drawable/car_02" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_windown"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="20dip" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_middle"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="68dip" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_bottom"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="103dip" />            </FrameLayout>        </LinearLayout>        <FrameLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_gravity="center" >            <ImageView                android:background="@drawable/car_03"                 android:id="@+id/entering_iv_carleft"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="240dip"               />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_top"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="430dip" />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_door"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="470dip"                android:layout_marginTop="45dip" />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_carwheels"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="350dip"                android:layout_marginTop="35dip" />        </FrameLayout>    </LinearLayout></LinearLayout>


布局文件entering_carpart02

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical" >    <LinearLayout        android:layout_width="match_parent"        android:layout_height="390dip"        android:gravity="center_horizontal"        android:orientation="vertical" >        <LinearLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_marginBottom="40dip"            android:layout_marginTop="20dip"            android:gravity="center_horizontal"            android:orientation="horizontal" >            <FrameLayout                android:layout_width="match_parent"                android:layout_height="wrap_content"                android:layout_gravity="center" >                <ImageView                    android:id="@+id/entering_iv_carpre"                    android:layout_width="293dip"                    android:layout_height="151dip"                    android:layout_marginLeft="100dip"                    android:background="@drawable/car_01" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPreWindow"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="240dip"                    android:layout_marginTop="8dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarLight"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="160dip"                    android:layout_marginTop="50dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPre"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="243dip"                    android:layout_marginTop="30dip" />                <ImageButton                    android:id="@+id/entering_imbtn_preCarPlate"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="243dip"                    android:layout_marginTop="83dip" />                <ImageView                    android:id="@+id/entering_iv_carbehind"                    android:layout_width="253dip"                    android:layout_height="162dip"                    android:layout_marginLeft="500dip"                    android:background="@drawable/car_02" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_windown"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="20dip" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_middle"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="68dip" />                <ImageButton                    android:id="@+id/entering_imbtn_behindCar_bottom"                    style="@style/entering_imageviewRed_style"                    android:layout_marginLeft="620dip"                    android:layout_marginTop="103dip" />            </FrameLayout>        </LinearLayout>        <FrameLayout            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:layout_gravity="center" >            <ImageView                android:background="@drawable/car_03"                 android:id="@+id/entering_iv_carleft"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginLeft="240dip"               />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_top"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="430dip" />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_door"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="470dip"                android:layout_marginTop="45dip" />            <ImageButton                android:id="@+id/entering_imbtn_sideCar_carwheels"                style="@style/entering_imageviewRed_style"                android:layout_marginLeft="350dip"                android:layout_marginTop="35dip" />        </FrameLayout>    </LinearLayout></LinearLayout>

java代码

在EnteringActivity.Activity java文件中

private ViewFlipper viewFlipper;// 定义一个手势识别器private GestureDetector mGestureDetector;@Overrideprotected void onCreate(Bundle savedInstanceState) {viewFlipper = (ViewFlipper) findViewById(R.id.entering_vf);mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {if (Math.abs(velocityX) < 100)return true;if (Math.abs(e2.getRawY() - e1.getRawY()) > 100)return true;if (e2.getRawX() - e1.getRawX() > 100) {// 从右到左的移动if (viewFlipper.getDisplayedChild() == 0) {//viewFlipper对象没有子view的时候,停止滑动                                                  viewFlipper.stopFlipping();                                                  return false;} else {showPre();return false;}}if (e2.getRawX() - e1.getRawX() < -100) {if (viewFlipper.getDisplayedChild() == 2 - 1) {//viewFlipper对象等于1的时候,停止滑动                                                 viewFlipper.stopFlipping();                                                 return false;} else {showNext();return false;}}return false;};});   关键就是要把  手势识别器 注册到 当前的Activity 的滑动方法里面@Overridepublic boolean onTouchEvent(MotionEvent event) {// 当手指在屏幕上触摸的时候 利用手势识别器 识别相应的动作mGestureDetector.onTouchEvent(event);return super.onTouchEvent(event);}     public void Imv1() {imvred.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.point_red)));imvpurple.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.position_point)));}public void Imv2() {imvred.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.position_point)));imvpurple.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.point_red)));}protected void showPre() {Animation outAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha_out);Animation inAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha_in);viewFlipper.setOutAnimation(outAnimation);viewFlipper.setInAnimation(inAnimation);viewFlipper.showPrevious();Imv1();}private void showNext() {Animation outAnimation = AnimationUtils.loadAnimation(this, R.anim.tran_out);Animation inAnimation = AnimationUtils.loadAnimation(this, R.anim.tran_in);viewFlipper.setOutAnimation(outAnimation);viewFlipper.setInAnimation(inAnimation);viewFlipper.showNext();Imv2();}

更多相关文章

  1. 布局(1、线性布局)
  2. android 写文件权限
  3. AndroidMenifest.xml(Android清单文件)内部代码分析
  4. Android布局文件中的属性含义
  5. Android开发进阶:如何读写Android文件
  6. android studio 使用adb命令传递文件到android设备
  7. Android 相对布局 RelativeLayout 属性

随机推荐

  1. 【Android(安卓)开发入门】android studi
  2. Android上app_process启动java进程
  3. Android(安卓)Gradle 学习笔记整理
  4. Android(安卓)应用程序之间数据共享—Con
  5. 【Appetite】ionic3实录(四)微调Segment,并
  6. Android(安卓)ART虚拟机(一)
  7. android 启动流程(中文)
  8. Android(安卓)中的数据绑定(1)
  9. eclipse adb 启动失败,无法匹配android设
  10. Android中ListView控件的简单使用