安卓学习第26课——textSwitcher

点击文字,实现文字转换,只用到了数组,还有动画效果,事件监听。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextSwitcher
        android:id="@+id/textSwitcher1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:inAnimation="@android:anim/slide_in_left"
        android:outAnimation="@android:anim/slide_out_right" 
        android:onClick="next"/>
</LinearLayout>
package com.example.textswitcher;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher.ViewFactory;

public class MainActivity extends Activity {

    TextSwitcher textSwitcher;
    String[] strs=new String[]{
            "高等数学",
            "线性代数",
            "离散数学",
            "安卓讲义"
    };
    int curStr;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textSwitcher=(TextSwitcher) findViewById(R.id.textSwitcher1);
        textSwitcher.setFactory(new ViewFactory(){

            @Override
            public View makeView() {
                TextView tv=new TextView(MainActivity.this);
                tv.setTextSize(40);
                tv.setTextColor(Color.MAGENTA);
                return tv;
            }
            
        });
        next(null);
    }
    public void next(View v) {
        textSwitcher.setText(strs[curStr++%strs.length]);
        
    }

    

}

 

转载于:https://www.cnblogs.com/Yvettey-me/p/3967112.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值