ViewFlipper realizes the effect of rolling up and down carousel
- 2021-11-13 02:40:09
- OfStack
1 kind of control that can set sliding animation, only display 1 line layout, and write the layout of each line in sequence in ViewFlipper control in layout file
(1).MainActivity.java:
ViewFlipper mFlipper = ((ViewFlipper) this.findViewById(R.id.flipper));
mFlipper.startFlipping();
// Setting Enter Animation
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_in));
// Set up roll-out animation
mFlipper.setOutAnimation(AnimationUtils.loadAnimation(this, R.anim.push_up_out));
(2).activity_main.xml:
<ViewFlipper
android:id="@+id/flipper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dip"
android:flipInterval="3000" > // Set the sliding interval (milliseconds)
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/animation_2_text_1"
android:textSize="26sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/animation_2_text_2"
android:textSize="26sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/animation_2_text_3"
android:textSize="26sp" />
</ViewFlipper>
(3). push_up_in. xml: (Animation resource file)
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
push_up_out.xml:
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>