zoukankan      html  css  js  c++  java
  • 安卓学习第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]);
            
        }
    
        
    
    }
  • 相关阅读:
    [STL][C++]MAP
    [原创]南水之源A*(A-Star)算法
    php+mysql模糊查询功能
    php中如何传递Session ID
    初识jsonp
    跨站脚本攻击XSS
    XSS危害——session劫持
    PHP中获取当前页面的完整URL
    smarty获得当前url的方法分享
    表空间的管理方式有哪几种,各有什么优劣?
  • 原文地址:https://www.cnblogs.com/Yvettey-me/p/3967112.html
Copyright © 2011-2022 走看看