Use Android circulation of the scroll control --ViewFlipper

  Suppose now that allows you to achieve a vertical cycle rolling effect, what is your first reaction? If you are looking for immediately think of a third party or custom (Hey! Really took the trouble), then you ViewFlipper are unfamiliar, explain this to your blog is valuable. Please read on:

  ViewFlipper is Android the basis of control, you may use very few people in the general development, so many developers feel very strange about this control, in the control circle ViewPager far more famous, but ViewFlipper usage is very simple, the effect is very Yes. First posted renderings:

      

A, ViewFlipper layout:


  
  
  1. <ViewFlipper
  2. android:id= "@+id/filpper"
  3. android:layout_width= "match_parent"
  4. android:layout_height= "wrap_content"
  5. android:autoStart= "true"
  6. android:flipInterval= "2000"
  7. android:inAnimation= "@anim/anim_come_in"
  8. android:outAnimation= "@anim/anim_get_out"/>

Into the animation anim_come_in:


  
  
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">
  3. <translate
  4. android:fromYDelta= "100%p"
  5. android:toYDelta= "0"
  6. android:duration= "1000"/>
  7. </set>
Slide-out animation anim_get_out:


  
  
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <set xmlns:android="http://schemas.android.com/apk/res/android">
  3. <translate
  4. android:fromYDelta= "0"
  5. android:toYDelta= "-100%p"
  6. android:duration= "1000"/>
  7. </set>
Two, ViewFlipper load interface layout

  Create a layout_custom, then according to the needs a custom interface layout can be, would not elaborate.

3. In order to load custom interface ViewFllipper

ViewFlipper viewFlipper= (ViewFlipper) findViewById(R.id.vf);
  
  

  
  
  1. for ( int i = 0; i < 5; i++) {
  2. View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_custom, null);
  3. viewFlipper.addView(view);
  4. }

Note: These are only five cycles ViewFlipper data loading method, the code is not Demo.

Four, ViewFlipper use Description

Methods xml layout description:

android: autoStart: View set to automatically load the next

android: flipInterval: View set the time interval of switching between

android: inAnimation: Set to enter the animation switch View

Exit animation settings switch View of: android: outAnimation

Of course, the same may also be provided in the code:

isFlipping: View determines handover is in progress

setFilpInterval: View set the time interval between the switching

startFlipping: View of the start switch, and will cycle

stopFlipping: Stop View switch

setOutAnimation: set an exit animation switch View,

setInAnimation: Set switch to enter the animation View

showNext: display ViewFlipper in the next View

showPrevious: on display ViewFlipper in a View

Published 154 original articles · won praise 89 · Views 100,000 +

Guess you like

Origin blog.csdn.net/qq_41933149/article/details/103899862