日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 中文 API —— TextSwitcher

發(fā)布時間:2025/1/21 Android 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android 中文 API —— TextSwitcher 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

聲明

  歡迎轉(zhuǎn)載,但請保留文章原始出處:)?

    madgoat:http://madgoat.cn/

    博客園:http://www.cnblogs.com

    農(nóng)民伯伯: http://www.cnblogs.com/over140/

?

版本

  Android 2.2 r1 ?

?

正文

  一、結(jié)構(gòu)

    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產(chǎn)生動畫效果。每當(dāng)setText(CharSequence)被調(diào)用時,TextSwitcher使用動畫方式將當(dāng)前的文字內(nèi)容消失并顯示新的文字內(nèi)容。(譯者注:改變文字時增加一些動畫效果)

?

  三、構(gòu)造函數(shù)

?????????public TextSwitcher (Context context)

?????????創(chuàng)建一個新的空TextSwitcher

???????????????????參數(shù)

context?應(yīng)用程序上下文

?

?????????public TextSwitcher (Context context, AttributeSet attrs)

?????????使用提供的contextattributes來創(chuàng)建一個空的TextSwitcher

???????????????????參數(shù)

??????????????????????????? context?應(yīng)用程序環(huán)境

??????????????????????????? attrs???????????????????屬性集合

?

  四、公共方法

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

?????????根據(jù)指定的布局參數(shù)新增一個子視圖

???????????????????參數(shù)

??????????????????????????? child??????????新增的子視圖

??????????????????????????? index?????????新增子視圖的位置

??????????????????????????? params????新增子視圖的布局參數(shù)

?????????拋出異常

?????????????????? IllegalArgumentException???????當(dāng)子視圖不是一個TextView實例時

?

?????????public void setCurrentText (CharSequence text)

?????????設(shè)置當(dāng)前顯示的文本視圖的文字內(nèi)容。非動畫方式顯示。

???????????????????參數(shù)

??????????????????????????? text???????????需要顯示的新文本內(nèi)容

?

?????????public void setText (CharSequence text)

?????????設(shè)置下一視圖的文本內(nèi)容并切換到下一視圖。可以動畫的退出當(dāng)前文本內(nèi)容,顯示下一文本內(nèi)容。

???????????????????參數(shù)

??????????????????????????? text???????????需要顯示的新文本內(nèi)容

?

  五、代碼示例

    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

?

結(jié)束

   madgoat非常積極,接到本章譯稿后就迅速的翻譯出來,并且附帶完善的代碼和截圖,現(xiàn)在已經(jīng)在翻譯下一篇譯稿,感謝他如此積極參與!


轉(zhuǎn)載于:https://my.oschina.net/sunxichao/blog/346149

總結(jié)

以上是生活随笔為你收集整理的Android 中文 API —— TextSwitcher的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。