zoukankan      html  css  js  c++  java
  • TextSwitcher 简单用例

    TextSwitcher 字面理解是文字交换器,是ViewSwitcher的子类,从ViewSwitcher来看,是View交换器,TextSwitcher继承自ViewSwitcher,显然是交换TextView。

    点击缓慢出现文字

    BaseActivity
    package com.shaoxin.mytextswitcher;
    
    import android.os.Bundle;
    import android.support.annotation.Nullable;
    import android.support.v7.app.AppCompatActivity;
    
    /**
     * Created by shaoxin on 2016/12/4.
     */
    
    public abstract class BaseActivity extends AppCompatActivity {
        public abstract void init();
    
        public abstract void listener();
    
        @Override
        protected void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            init();
            listener();
        }
    }
    MainActivity
    package com.shaoxin.mytextswitcher;
    
    import android.os.Bundle;
    import android.view.View;
    import android.view.animation.AnimationUtils;
    import android.widget.Button;
    import android.widget.TextSwitcher;
    import android.widget.TextView;
    import android.widget.ViewSwitcher;
    
    public class MainActivity extends BaseActivity {
        private TextSwitcher textswitcher;
        private Button btn;
        private ViewSwitcher.ViewFactory factory;
    
        @Override
        public void init() {
            setContentView(R.layout.activity_main);
            textswitcher = (TextSwitcher) findViewById(R.id.textswitcher);
            btn = (Button) findViewById(R.id.btn);
        }
    
        @Override
        public void listener() {
            factory = new ViewSwitcher.ViewFactory() {
                @Override
                public View makeView() {
                    TextView textView = new TextView(MainActivity.this);
                    textView.setTextSize(40);
                    return textView;
                }
            };
            textswitcher.setFactory(factory);
            btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    textswitcher.setInAnimation(AnimationUtils
                            .loadAnimation(MainActivity.this, android.R.anim.fade_in));
                    textswitcher.setInAnimation(AnimationUtils
                            .loadAnimation(MainActivity.this, android.R.anim.fade_out));
                    textswitcher.setText("hello");
                }
            });
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        }
    }

    activity_main.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 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:orientation="vertical"
        tools:context="com.shaoxin.mytextswitcher.MainActivity">
    
        <Button
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="点击出现" />
    
        <TextSwitcher
            android:id="@+id/textswitcher"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    
    
    </LinearLayout>
  • 相关阅读:
    SpringBoot接收前端参数的三种方法
    拉姆达表达式入门
    Can not issue data manipulation statements with executeQuery()错误解决
    executing an update/delete query问题
    syntax error, error in :'e id=1?', expect QUES, actual QUES pos 66, line 1, column 66, token QUES错误
    SpringDataJpa错误
    No identifier specified for entity: XXXX 错误
    An entity cannot be annotated with both @Entity and @MappedSuperclass: com.example1.demo1.Entity.User错误
    org.hibernate.AnnotationException: No identifier specified for entity: com.example1.demo1.Entity.User错误
    base64转图片
  • 原文地址:https://www.cnblogs.com/ShaoXin/p/6171303.html
Copyright © 2011-2022 走看看