最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android開發(fā)實現(xiàn)自動切換文字TextSwitcher功能示例

 更新時間:2019年03月22日 08:49:07   作者:水中魚之1999  
這篇文章主要介紹了Android開發(fā)實現(xiàn)自動切換文字TextSwitcher功能,結(jié)合實例形式詳細分析了Android使用TextSwitcher實現(xiàn)文字自動切換的原理、實現(xiàn)方法及相關(guān)操作注意事項,需要的朋友可以參考下

本文實例講述了Android開發(fā)實現(xiàn)自動切換文字TextSwitcher功能。分享給大家供大家參考,具體如下:

介紹:

1.TextSwitcher是ViewSwicher的一個子類,繼承了ViewSwicher的所有方法

2.與ViewSwitcher的另一個子類類似,TextSwitcher也有

3.ImageSwitcher不同的是:TextSwitcher的ViewFactory方法的 makeVieW() 必須放回一個TextXiew組件.

具體效果:

放射思維:

如果將其和輪播圖(http://m.fzitv.net/article/158149.htm)結(jié)合 就可以實現(xiàn)帶文字效果的輪播圖。

這里先給出布局文件:

<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:gravity="center_horizontal">
    <!--定義一個ViewSwitcher并且制定了文本切換時的動畫效果-->
    <TextSwitcher
      android:id="@+id/textSwitcher"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:inAnimation="@android:anim/slide_in_left"
      android:outAnimation="@android:anim/slide_out_right"
      android:onClick="next">
    </TextSwitcher>
</RelativeLayout>

關(guān)于文字定時切換的實現(xiàn):

1.首先寫一個next方法,再這個歌方法中調(diào)用父類的setText()方法 實現(xiàn)了文字的設(shè)定

2.再主線程中開設(shè)一個性的線程用于圖片的切換 注意:線程中不能直接改變View,所以要發(fā)送小修再Handler對象中改變布局內(nèi)容(文字)

實現(xiàn)如下:

public class MainActivity extends Activity {
  String[] string = new String[]{
      "我愛高數(shù)",
      "我愛概率論",
      "我愛計算機網(wǎng)絡(luò)",
      "我愛操作系統(tǒng)"
  };
  TextSwitcher textSwitcher;
  int curStr ;
  Handler handler = new Handler(){
    @Override
    public void handleMessage(Message msg) {
      next(null);
    }
  };
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    textSwitcher = (TextSwitcher) findViewById(R.id.textSwitcher);
    textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
      @Override
      public View makeView() {
        TextView textView = new TextView(MainActivity.this);
        textView.setTextSize(40);
        textView.setTextColor(Color.RED);
        return textView;
      }
    });
    new Thread(){
      @Override
      public void run() {
        while (true){
          Message message = handler.obtainMessage();
          message.obj = 0;
          handler.sendMessage(message);
          try {
            sleep(1000);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }.start();
  }
  private void next(View scource){
    textSwitcher.setText(string[curStr = ( curStr++ % string.length )]);
  }
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android圖形與圖像處理技巧總結(jié)》、《Android開發(fā)入門與進階教程》、《Android調(diào)試技巧與常見問題解決方法匯總》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)

希望本文所述對大家Android程序設(shè)計有所幫助。

相關(guān)文章

最新評論

太谷县| 融水| 武宁县| 临沧市| 凤翔县| 当涂县| 克拉玛依市| 常宁市| 灵台县| 金昌市| 义马市| 合作市| 当雄县| 梨树县| 江阴市| 页游| 宝兴县| 滕州市| 隆化县| 天全县| 亳州市| 承德县| 于都县| 河池市| 页游| 克山县| 鄯善县| 怀远县| 汉寿县| 富蕴县| 青田县| 甘洛县| 万州区| 贺州市| 哈巴河县| 平邑县| 秦安县| 会泽县| 苏州市| 乌鲁木齐县| 永新县|