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:
-
<ViewFlipper
-
android:id=
"@+id/filpper"
-
android:layout_width=
"match_parent"
-
android:layout_height=
"wrap_content"
-
android:autoStart=
"true"
-
android:flipInterval=
"2000"
-
android:inAnimation=
"@anim/anim_come_in"
-
android:outAnimation=
"@anim/anim_get_out"/>
Into the animation anim_come_in:
-
<?xml version="1.0" encoding="utf-8"?>
-
<set xmlns:android="http://schemas.android.com/apk/res/android">
-
-
<translate
-
android:fromYDelta=
"100%p"
-
android:toYDelta=
"0"
-
android:duration=
"1000"/>
-
</set>
Slide-out animation anim_get_out:
-
<?xml version="1.0" encoding="utf-8"?>
-
<set xmlns:android="http://schemas.android.com/apk/res/android">
-
-
<translate
-
android:fromYDelta=
"0"
-
android:toYDelta=
"-100%p"
-
android:duration=
"1000"/>
-
</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);
-
for (
int i =
0; i <
5; i++) {
-
View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.layout_custom,
null);
-
viewFlipper.addView(view);
-
}
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