Android ViewFlipper简单应用
AndroidViewFlipper简单应用,废话不多说,直接看代码
activity_guide.xml
<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/guide" tools:context="com.example.weijian.homeletterapplication.GuideActivity"> <ViewFlipper android:id="@+id/Main_ViewFlipper" android:layout_width="match_parent" android:layout_height="match_parent"> </ViewFlipper> </LinearLayout>
GuideActivity.java
importandroid.content.Intent; importandroid.support.v7.app.ActionBar; importandroid.support.v7.app.AppCompatActivity; importandroid.os.Bundle; importandroid.view.GestureDetector; importandroid.view.MotionEvent; importandroid.view.View; importandroid.view.WindowManager; importandroid.widget.ImageView; importandroid.widget.ViewFlipper; publicclassGuideActivityextendsAppCompatActivityimplementsGestureDetector.OnGestureListener{ privateGestureDetectordetector; privateViewFlipperflipper; @Override protectedvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_guide); //隐藏标题栏 ActionBaractionBar=getSupportActionBar(); actionBar.hide(); detector=newGestureDetector(this); flipper=(ViewFlipper)this.findViewById(R.id.Main_ViewFlipper); flipper.addView(addImageView(R.mipmap.guide1)); flipper.addView(addImageView(R.mipmap.guide2)); flipper.addView(addImageView(R.mipmap.guide3)); } privateViewaddImageView(intid){ ImageViewiv=newImageView(this); //ImageView拉伸,充满整个ViewFlipper iv.setScaleType(ImageView.ScaleType.FIT_XY); iv.setImageResource(id); returniv; } @Override publicbooleanonTouchEvent(MotionEventevent){ //TODOAuto-generatedmethodstub returnthis.detector.onTouchEvent(event); } @Override publicbooleanonDown(MotionEvente){ //TODOAuto-generatedmethodstub returnfalse; } @Override publicbooleanonFling(MotionEvente1,MotionEvente2,floatvelocityX, floatvelocityY){ if(e1.getX()-e2.getX()>120){ this.flipper.showNext(); } if(e1.getX()-e2.getX()<-120){ this.flipper.showPrevious(); } returnfalse; } @Override publicvoidonLongPress(MotionEvente){ //TODOAuto-generatedmethodstub } @Override publicbooleanonScroll(MotionEvente1,MotionEvente2,floatdistanceX, floatdistanceY){ //TODOAuto-generatedmethodstub returnfalse; } @Override publicvoidonShowPress(MotionEvente){ //TODOAuto-generatedmethodstub } @Override publicbooleanonSingleTapUp(MotionEvente){ //TODOAuto-generatedmethodstub returnfalse; } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。