SoFunction
Updated on 2025-04-09

ViewFlipper realizes up and down scrolling effect

A control that can set sliding animations, displays only one line of layout, and writes the layout of each line in the ViewFlipper control in the layout file.

(1).:

ViewFlipper mFlipper = ((ViewFlipper) ());
();
// Set the entry animation((this, .push_up_in)); 
// Set the rollout animation((this, .push_up_out)); 

(2).activity_main.xml:

<ViewFlipper
  android:
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginBottom="20dip"
  android:flipInterval="3000" > // Set the sliding interval time (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:andro>
  <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:andro>
  <translate android:fromYDelta="0" android:toYDelta="-100%p" android:duration="300"/>
  <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="300" />
</set>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.