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>
TextSwitcher 简单用例的更多相关文章
- extern外部方法使用C#简单样例
外部方法使用C#简单样例 1.添加引用using System.Runtime.InteropServices; 2.声明和实现的连接[DllImport("kernel32", ...
- spring事务详解(二)简单样例
系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...
- Docker Compose 创建yml 简单试例
Docker Compose 创建yml 简单试例 Docker Compose 文件使用格式版本需要与Docker版本对应可在官网内查找 查找地址:https://docs.docker.com/c ...
- webpack -- 多页面简单小例
有时单页面并不能满足我们的业务需求,就需要去构建多页面应用,以下为简单小例: entry:{ index:'./src/module/index/index.js', student:'./src/m ...
- velocity简单样例
velocity简单样例整体实现须要三个步骤,详细例如以下: 1.创建一个Javaproject 2.导入须要的jar包 3.创建须要的文件 ============================= ...
- 自己定义隐式转换和显式转换c#简单样例
自己定义隐式转换和显式转换c#简单样例 (出自朱朱家园http://blog.csdn.net/zhgl7688) 样例:对用户user中,usernamefirst name和last name进行 ...
- php libevent扩展的简单用例
php libevent扩展具有很强大的功能.以下摘自百度百科: Libevent 是一个用C语言编写的.轻量级的开源高性能网络库,主要有以下几个亮点:事件驱动( event-driven),高性能; ...
- VC6 鼠标钩子 最简单样例
Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消息的传递来实现的.而钩子是Windows系统中非常重要的系统接口,用它能够截获并处理送给其它应用程序的消息,来完毕普通应用程序 ...
- gtk+3.0的环境配置及基于gtk+3.0的python简单样例
/********************************************************************* * Author : Samson * Date ...
随机推荐
- 加载dll过程中assembly失败
错误现象: 进行插件读取时出现错误:“尝试从一个网络位置加载程序集,在早期版本的 .NET Framework 中,这会导致对该程序集进行沙盒处理.此发行版的 .NET Framework 默认情况下 ...
- Traditional Language Model
Traditional Language Model通常用于回答下述问题: How likely is a string of English words good English ? \(p_{LM ...
- ionic 微信分享值各种坑
去前段时间公司的app需要做微信分享,然后网上找的教程,在做的时候发现网上的教程各种坑,现在将做得过程分享出来 在做功能之前你需要做几步预备工作, 1.安装jdk,jre,并加入全局变量[这个网上还是 ...
- linux REDHAT6.4下安装ArcGIS Server 10.1
1 安装环境 因为Linux的发行版本比较多,我们在使用的时候请严格按照官网给的给出的版本,在官网上给出的是经过严格测试的,如果采用其他的,即便安装上了,在后续的运作中出现问题,这个可就麻烦了,官网对 ...
- Android开发环境的搭建
在学习android时,环境的搭建是学习android的第一步,为了记住第一步特写了这篇文章. 第一步,安装jdk,因为eclipse的运行需要jdk才可以,所以jdk的安装时第一步.安装过程和普通的 ...
- 使用MicroService4Net 快速创建一个简单的微服务
“微服务架构(Microservice Architecture)”一词在过去几年里广泛的传播,它用于描述一种设计应用程序的特别方式,作为一套独立可部署的服务.目前,这种架构方式还没有准确的定义,但是 ...
- 巧用setTimeout解决阻塞导致页面无法重绘
项目中遇到一个javascript问题,大致如下: <!doctype HTML> <html> <head> <meta charset="utf ...
- 深入理解javascript原型和闭包(9)——简述【执行上下文】下
继续上一篇文章(http://www.cnblogs.com/wangfupeng1988/p/3986420.html)的内容. 上一篇我们讲到在全局环境下的代码段中,执行上下文环境中有如何数据: ...
- ThinkPHP中疑难笔记
不但要记住核心的东西, 还要记住 相关的 东西: 如php cli的版本是 5.6.14 bulit: sep 30, 2015 tp中, 通常说的系统就是框架; 项目就是 "应用程序&qu ...
- 深入理解java异常处理机制
异常指不期而至的各种状况,如:文件找不到.网络连接失败.非法参数等.异常是一个事件,它发生在程序运行期间,干扰了正常的指令流程.Java通 过API中Throwable类的众多子类描述各种不同的 ...