• 安卓学习第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]);
            
        }
    
        
    
    }
  • 相关阅读:
    用户需求调研报告
    返回一个二维数组中的最大联通子数组(补)
    代码大全读后感(3)
    代码大全读后感(2)
    返回一个二维整数数组中最大联通子数组的和
    冲刺第一阶段总结
    大道至简读书笔记三
    大道至简读书笔记二
    大道至简读书笔记一
    软件工程课程改进意见
  • 原文地址:https://www.cnblogs.com/Yvettey-me/p/3967112.html
Copyright © 2020-2023  润新知