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

Android 自定義控件實(shí)現(xiàn)顯示文字的功能

 更新時(shí)間:2016年11月11日 15:59:57   投稿:lqh  
這篇文章主要介紹了Android 自定義控件實(shí)現(xiàn)顯示文字的功能的相關(guān)資料,需要的朋友可以參考下

Android 自定義控件實(shí)現(xiàn)顯示文字的功能

自定義控件—–逐個(gè)顯示文字

ONE Goal ,ONE Passion !

前言:

今天要實(shí)現(xiàn)的效果時(shí).讓我們的文字一個(gè)一個(gè)顯示出來.上效果圖吧:

實(shí)現(xiàn)原理:

1,拿到要顯示的文字.

2,計(jì)算文字顯示的速率
字體顯示的速度 v = 總的字體長(zhǎng)度 / 總的顯示時(shí)間

3,將文字根據(jù)速率顯示到控件上.

自定義View:

 public class printTextView extends TextView {

  /**
   * 字體顯示出來的時(shí)間
   */
  private int DURATION = 8000;

  public printTextView(Context context) {
    this(context, null);
  }

  public printTextView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public printTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);


  }


  public void printString(String str) {


    if (str != null && str != "") {

      // 字符串的長(zhǎng)度
      final int lenght = str.length();


      final char[] c = new char[str.length()];
      //將字符串轉(zhuǎn)換成字符數(shù)組
      for (int i = 0; i < str.length(); i++) {
        c[i] = str.charAt(i);
      }


      ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
      animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

          // 字體顯示的速度 v = 總的字體長(zhǎng)度 / 總的顯示時(shí)間
          float v = (float) lenght / (float) DURATION;
          // 動(dòng)畫執(zhí)行速度
          float fraction = (float) animation.getAnimatedValue();
          //動(dòng)畫不同階段字體應(yīng)該顯示的個(gè)數(shù)
          int s = (int) (v * fraction * DURATION);

          setText(c, 0, s);

        }
      });
      animator.setDuration(DURATION);
      animator.start();
    }


  }


  }

跑起來:

 

 public class ScaleActivity extends AppCompatActivity {


  private printTextView print_text;
  String str = "我和你吻別,在無人的街.我和你吻別在狂亂的夜.這波給你103分," +
      "多一分寬容,多一分耐心,更重要的是多一分父愛.";

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scale);
    initView();
  }




    print_text = (printTextView) findViewById(R.id.print_text);
    print_text.printString(str);
  }
  }

R.layout.activity_scale布局文件

 <?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:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_margin="20dp"
  android:orientation="vertical"
  tools:context="com.example.customview.activity.ScaleActivity">
 <com.example.customview.view.printTextView
    android:id="@+id/print_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
 />
 </LinearLayout>

ok.我們的文字已經(jīng)可以打印顯示到屏幕了.

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

  • Android7.0指紋服務(wù)FingerprintService實(shí)例介紹

    Android7.0指紋服務(wù)FingerprintService實(shí)例介紹

    這篇文章主要介紹了Android7.0指紋服務(wù)FingerprintService介紹,需要的朋友可以參考下
    2018-01-01
  • Android自定義視圖中圖片的處理

    Android自定義視圖中圖片的處理

    Android系統(tǒng)提供了ImageView顯示普通的靜態(tài)圖片,也提供了AnimationDrawable來開發(fā)逐幀動(dòng)畫,還可通過Animation對(duì)普通圖片使用補(bǔ)間動(dòng)畫。圖形、圖像處理不僅對(duì)Android系統(tǒng)的應(yīng)用界面非常重要,而且Android系統(tǒng)上的益智類游戲、2D游戲都需要大量的圖形、圖像處理
    2022-07-07
  • Android中Socket的應(yīng)用分析

    Android中Socket的應(yīng)用分析

    這篇文章主要介紹了Android中Socket的應(yīng)用,結(jié)合實(shí)例形式分析了Android中socket通信的實(shí)現(xiàn)技巧與相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2016-10-10
  • Android編程設(shè)計(jì)模式之策略模式詳解

    Android編程設(shè)計(jì)模式之策略模式詳解

    這篇文章主要介紹了Android編程設(shè)計(jì)模式之策略模式,結(jié)合實(shí)例形式詳細(xì)分析了Android策略模式的概念、原理、實(shí)現(xiàn)方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2017-12-12
  • 源碼淺析Android中內(nèi)存泄漏檢測(cè)工具Leakcanary的使用

    源碼淺析Android中內(nèi)存泄漏檢測(cè)工具Leakcanary的使用

    大名鼎鼎的 Leakcanary 想必作為 Android 開發(fā)都多多少少接觸過,新版本的 Leakcanary 也用 Kotlin 重寫了一遍,最近詳細(xì)查看了下源碼,就來和大家簡(jiǎn)單分享一下
    2023-04-04
  • Android系列之Intent傳遞對(duì)象的幾種實(shí)例方法

    Android系列之Intent傳遞對(duì)象的幾種實(shí)例方法

    Android系列之Intent傳遞對(duì)象的幾種實(shí)例方法,需要的朋友可以參考一下
    2013-05-05
  • Android System fastboot 介紹和使用教程

    Android System fastboot 介紹和使用教程

    Fastboot是Android快速升級(jí)的一種方法,Fastboot的協(xié)議fastboot_protocol.txt在源碼目錄./bootable/bootloader/legacy下可以找到,本文給大家介紹Android System fastboot 介紹和使用教程,感興趣的朋友一起看看吧
    2024-01-01
  • Android的VSYNC機(jī)制和UI刷新流程示例詳解

    Android的VSYNC機(jī)制和UI刷新流程示例詳解

    這篇文章主要為大家介紹了Android的VSYNC機(jī)制和UI刷新流程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-12-12
  • Android DrawLayout結(jié)合ListView用法實(shí)例

    Android DrawLayout結(jié)合ListView用法實(shí)例

    這篇文章主要介紹了Android DrawLayout結(jié)合ListView用法實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Android自定義TitleView標(biāo)題開發(fā)實(shí)例

    Android自定義TitleView標(biāo)題開發(fā)實(shí)例

    這篇文章主要介紹了Android自定義TitleView標(biāo)題開發(fā)實(shí)例的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-09-09

最新評(píng)論

永和县| 邻水| 赫章县| 汨罗市| 红河县| 开鲁县| 安吉县| 彭州市| 阜新| 依安县| 泰州市| 贡嘎县| 板桥市| 九龙城区| 治县。| 鄱阳县| 临邑县| 祁阳县| 安庆市| 新泰市| 石狮市| 荣成市| 交口县| 三台县| 铜梁县| 枣庄市| 高唐县| 喀什市| 合作市| 剑川县| 长沙县| 阜新| 云浮市| 庆阳市| 海口市| 板桥市| 正镶白旗| 吉木萨尔县| 涟水县| 买车| 罗源县|