Android 中文 API (17) —— TextSwitcher

简介:

一、结构

    public class TextSwitcher extends ViewSwitcher

    java.lang.Object

      android.view.View

        android.view.ViewGroup

          android.widget.FrameLayout

                              android.widget.ViewAnimator

                                    android.widget.ViewSwitcher

                                          android.widget.TextSwitcher

二、类概述

    

    ViewSwitcher仅仅包含子类型TextView。TextSwitcher被用来使屏幕上的label产生动画效果。每当setText(CharSequence)被调用时,TextSwitcher使用动画方式将当前的文字内容消失并显示新的文字内容。(译者注:改变文字时增加一些动画效果)

三、构造函数

         public TextSwitcher (Context context)

         创建一个新的空TextSwitcher

                   参数

context 应用程序上下文

         public TextSwitcher (Context context, AttributeSet attrs)

         使用提供的contextattributes来创建一个空的TextSwitcher

                   参数

                            context 应用程序环境

                            attrs                   属性集合

四、公共方法

         public void addView (View child, int index, ViewGroup.LayoutParams params)

         根据指定的布局参数新增一个子视图

                   参数

                            child          新增的子视图

                            index         新增子视图的位置

                            params    新增子视图的布局参数

         抛出异常

                   IllegalArgumentException       当子视图不是一个TextView实例时

         public void setCurrentText (CharSequence text)

         设置当前显示的文本视图的文字内容。非动画方式显示。

                   参数

                            text           需要显示的新文本内容

         public void setText (CharSequence text)

         设置下一视图的文本内容并切换到下一视图。可以动画的退出当前文本内容,显示下一文本内容。

                   参数

                            text           需要显示的新文本内容

五、代码示例

    5.1  摘自APIDemos->View->TextSwitcher

      5.1.1  Java

public   class  TextSwitcher1  extends  Activity  implements  ViewSwitcher.ViewFactory,
        View.OnClickListener {

    
private  TextSwitcher mSwitcher;

    
private   int  mCounter  =   0 ;

    @Override
    
protected   void  onCreate(Bundle savedInstanceState) {
        
super .onCreate(savedInstanceState);

        setContentView(R.layout.text_switcher_1);

        mSwitcher 
=  (TextSwitcher) findViewById(R.id.switcher);
        mSwitcher.setFactory(
this );

        Animation in 
=  AnimationUtils.loadAnimation( this ,
                android.R.anim.fade_in);
        Animation out 
=  AnimationUtils.loadAnimation( this ,
                android.R.anim.fade_out);
        mSwitcher.setInAnimation(in);
        mSwitcher.setOutAnimation(out);

        Button nextButton 
=  (Button) findViewById(R.id.next);
        nextButton.setOnClickListener(
this );

        updateCounter();
    }

    
public   void  onClick(View v) {
        mCounter
++ ;
        updateCounter();
    }

    
private   void  updateCounter() {
        mSwitcher.setText(String.valueOf(mCounter));
    }

    
public  View makeView() {
        TextView t 
=   new  TextView( this );
        t.setGravity(Gravity.TOP 
|  Gravity.CENTER_HORIZONTAL);
        t.setTextSize(
36 );
        
return  t;
    }
}

      5.1.2  XML

<? xml version="1.0" encoding="utf-8" ?>
< LinearLayout  xmlns:android ="http://schemas.android.com/apk/res/android"
    android:layout_width
="match_parent"
    android:layout_height
="match_parent"
    android:orientation
="vertical" >

    
< Button  android:id ="@+id/next"
        android:layout_width
="wrap_content"
        android:layout_height
="wrap_content"  
        android:text
="@string/text_switcher_1_next_text"   />

    
< TextSwitcher  android:id ="@+id/switcher"
        android:layout_width
="match_parent"
        android:layout_height
="wrap_content"   />

</ LinearLayout >

    5.2  其他示例

      http://tech.ddvip.com/2010-02/1265125017144500.html

      http://www.javaeye.com/topic/569985

六、下载

    CSDN:http://download.csdn.net/source/2774515

本文转自博客园农民伯伯的博客,原文链接:Android 中文 API (17) —— TextSwitcher,如需转载请自行联系原博主。

目录
相关文章
|
8月前
|
定位技术 API 开发工具
Android 按照步骤接入百度地图API,定位显示不了解决办法
Android 按照步骤接入百度地图API,定位显示不了解决办法
225 0
|
7月前
|
API Android开发
mPaaS(移动跨平台框架)目前已经支持了Android API级别21
mPaaS(移动跨平台框架)目前已经支持了Android API级别21
106 2
|
8月前
|
API 数据库 Android开发
Android SQLite数据库中基础的增删改查操作以及API的详解
Android SQLite数据库中基础的增删改查操作以及API的详解
65 0
|
10月前
|
API Android开发
Android Activity Result API
Android Activity Result API
98 0
|
11月前
|
Java API Android开发
Sui为根应用提供Java APIs,滴API。主要提供直接使用Android APIs的能力(几乎以Java作为root的身份
Sui为根应用提供Java APIs,滴API。主要提供直接使用Android APIs的能力(几乎以Java作为root的身份,在root下启动app自己的AIDL风格的Java服务。这将使root应用程序开发变得更加容易。
142 0
|
12月前
|
缓存 Java API
Android音频API
MediaRecorder与MediaPlayer并不能算完整意义的音频API,它们只是系统音频API的封装,除了采集/播放,他们集成了编码/解码、复用/解复用等能力。它们在最底层还是调用了AudioRecorder、AudioTrack。下面主要介绍它们的几个主要的配置项。
357 0
|
Ubuntu Java Shell
Android使用FFmpeg的API库
Android使用FFmpeg的API库
293 1
|
定位技术 API Android开发
Android Studio进行APP设计调用百度地图API接口隐藏百度地图的logo方法
Android Studio进行APP设计调用百度地图API接口隐藏百度地图的logo方法
315 0
Android Studio进行APP设计调用百度地图API接口隐藏百度地图的logo方法
|
存储 缓存 Java
Android 百度语音合成 (含离线、在线、API合成方式,详细步骤+源码)
Android 百度语音合成 (含离线、在线、API合成方式,详细步骤+源码)
499 0
Android 百度语音合成 (含离线、在线、API合成方式,详细步骤+源码)
|
XML API Android开发
Android 垃圾分类APP(一)申请API、搭建项目、访问接口获取数据
Android 垃圾分类APP(一)申请API、搭建项目、访问接口获取数据
370 0
Android 垃圾分类APP(一)申请API、搭建项目、访问接口获取数据