Android(安卓)中文 API (17) —— TextSwitcher
前言
本章内容是android.widget.TextSwitcher,译为文字转换器控件(引自系出名门系列),翻译来自madgoat ,欢迎大家访问他的博客:http://madgoat.cn/,再次感谢 madgoat !期待你一起参与Android API 的中文翻译,联系我over140@gmail.com。
声明
欢迎转载,但请保留文章原始出处:)
madgoat:http://madgoat.cn/
博客园:http://www.cnblogs.com
农民伯伯: http://www.cnblogs.com/over140/
版本
Android 2.2 r1正文
一、结构
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)
使用提供的context和attributes来创建一个空的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 TextSwitchermSwitcher;
private int mCounter = 0 ;
@Override
protected void onCreate(BundlesavedInstanceState){
super .onCreate(savedInstanceState);
setContentView(R.layout.text_switcher_1);
mSwitcher = (TextSwitcher)findViewById(R.id.switcher);
mSwitcher.setFactory( this );
Animationin = AnimationUtils.loadAnimation( this ,
android.R.anim.fade_in);
Animationout = AnimationUtils.loadAnimation( this ,
android.R.anim.fade_out);
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
ButtonnextButton = (Button)findViewById(R.id.next);
nextButton.setOnClickListener( this );
updateCounter();
}
public void onClick(Viewv){
mCounter ++ ;
updateCounter();
}
private void updateCounter(){
mSwitcher.setText(String.valueOf(mCounter));
}
public ViewmakeView(){
TextViewt = new TextView( this );
t.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
t.setTextSize( 36 );
return t;
}
}
5.1.2 XML
<? xmlversion="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
结束
madgoat非常积极,接到本章译稿后就迅速的翻译出来,并且附带完善的代码和截图,现在已经在翻译下一篇译稿,感谢他如此积极参与!
更多相关文章
- Android内容提供者(ContentProvider)浅析(二)
- spring mvc dubbo ios android整合cms内容发布平台
- Android腾讯微薄客户端开发六:给用户加VIP认证以及美化微博显示
- spring mvc + mybatis 构建 cms 内容发布系统 ios android
- Retrofit的详解及使用
- Flutter-基础组件2
- Ubuntu中手动安装配置JDK, Android(安卓)SDK, NDK
- HttpClient and HttpURLConnection——Android(一)
- Android(安卓)studio 3.5安装详解