Android之View提升:二 使用 TextSwitcher 平滑切换多个标题
1. 知识点
-
ViewSwitcher 参考网页
参考博客
ViewSwitcher继承ViewAnimator,主要用于视图的切换。
ViewSwitcher重写了addView(View, int, ViewGroup.LayoutParams)方法,使其子控件不超过2个。
2. 效果展示:
3. 代码实现:
package cn.study.project.textswitcher;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity implements ViewSwitcher.ViewFactory {
private TextSwitcher mTextSwitcher;
private int myID=0;
String[] myItems={
"神奇宝贝1","神奇宝贝2","神奇宝贝3","神奇宝贝