Viewflipper to achieve text rotation effect

Viewflipper realizes text rotation (imitating Taobao headlines and vertical scrolling advertisements) for your reference. The specific contents are as follows

As can be seen from the source code, in fact, viewflipper indirectly inherits FrameLayout. It can also be said that viewflipper is actually a FrameLayout, which just encapsulates a loop between the animation implementation and the handler implementation.

Layout file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <!--android:autoStart:设置自动加载下一个View-->
 <!--android:flipInterval:设置View之间切换的时间间隔-->
 <!--android:inAnimation:设置切换View的进入动画-->
 <!--android:outAnimation:设置切换View的退出动画-->
 <ViewFlipper

  android:id="@+id/view_flipper"
  android:layout_width="match_parent"
  android:layout_height="100dp"
  android:layout_centerInParent="true"
  android:autoStart="true"
  android:background="#808080"
  android:flipInterval="2000"
  android:inAnimation="@anim/slide_in_down"
  android:outAnimation="@anim/slide_out_up">

  <TextView
   android:id="@+id/first"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:text="白日依山尽"
   android:textColor="#FF00FF"
   android:textSize="50sp" />

  <TextView
   android:id="@+id/second"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:text="黄河入海流"
   android:textColor="#FF00FF"
   android:textSize="50sp" />

  <TextView
   android:id="@+id/third"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:text="欲穷千里目"
   android:textColor="#FF00FF"
   android:textSize="50sp" />

  <TextView
   android:id="@+id/forth"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_gravity="center"
   android:text="更上一层楼"
   android:textColor="#FF00FF"
   android:textSize="50sp" />
 </ViewFlipper>
</RelativeLayout>

Here we introduce the properties used by viewflipper. In fact, these properties can be implemented in code, but they are placed in the layout for the sake of the appearance of the code

The following is an introduction to the common methods of viewflipper. In addition to setting the above properties, other methods are also provided

Two animations are also involved here. In fact, they are a pan animation, which are saved in the anim folder

slide_ in_ Down.xml to enter the animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
 <translate
  android:duration="@android:integer/config_mediumAnimTime"
  android:fromYDelta="100%"
  android:toYDelta="0"/>
</set>

slide_ out_ Up.xml exit animation

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
 android:duration="@android:integer/config_mediumAnimTime"
 android:fromYDelta="0"
 android:toYDelta="-100%"/>
</set>

MainActivity

package com.nrf.mydemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

 }

}

After running, the renderings

The above is the whole content of this article. I hope it will help you in your study, and I hope you will support us a lot.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>