久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

如何用Android實(shí)現(xiàn)文字消除效果-創(chuàng)新互聯(lián)

這篇文章主要介紹“如何用Android實(shí)現(xiàn)文字消除效果”,在日常操作中,相信很多人在如何用Android實(shí)現(xiàn)文字消除效果問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”如何用Android實(shí)現(xiàn)文字消除效果”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!

成都創(chuàng)新互聯(lián)公司是一家專注于成都網(wǎng)站設(shè)計(jì)、網(wǎng)站制作與策劃設(shè)計(jì),五蓮網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專注于網(wǎng)站建設(shè)十余年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:五蓮等地區(qū)。五蓮做網(wǎng)站價(jià)格咨詢:18982081108

先看效果圖:

如何用Android實(shí)現(xiàn)文字消除效果

由于項(xiàng)目和語(yǔ)音識(shí)別相關(guān),有時(shí)候人在不經(jīng)意間交流的無(wú)效音頻會(huì)被識(shí)別出來(lái),并展示于界面,為了美觀,客戶要求我們將這些無(wú)效的識(shí)別文本用一個(gè)從右到左的動(dòng)畫(huà)給清除,于是便有了下述的技術(shù)實(shí)現(xiàn)。

嗯,效果做完后發(fā)現(xiàn)原理及其簡(jiǎn)單,僅此記錄一下。

1、layout文件先在這兒貼一下

<?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">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="44dp"
        android:text="百日不到處,青春恰自來(lái)。苔花如米小,也學(xué)牡丹開(kāi)。"
        android:ellipsize="none"
        android:singleLine="true"
        android:background="#ff00ff"
        android:layout_marginTop="10dp"
        android:id="@+id/tv_text"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn_click"
        android:text="點(diǎn)擊清除"/>
        
  <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btn_click1"
        android:text="點(diǎn)擊恢復(fù)"/>
</LinearLayout>

btn_click1是為了演示方便而設(shè)計(jì)的,可不計(jì)考慮。注意TextView中需要:

android:ellipsize="none"
android:singleLine="true"

兩個(gè)屬性,該效果只針對(duì)一行的文本。

2、貼一下java代碼

public class MainActivity extends AppCompatActivity {
    private TextView textView;
    private Button btn_click;
    private Button btn_click1;
    private Handler mHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mHandler = new Handler();
        textView = findViewById(R.id.tv_text);
        btn_click = findViewById(R.id.btn_click);
        btn_click1 = findViewById(R.id.btn_click1);
        btn_click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showAsrAnim();
            }
        });

        btn_click1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                textView.setVisibility(View.VISIBLE);
                textView.setText("百日不到處,青春恰自來(lái)" +"苔花如米小,也學(xué)牡丹開(kāi)。");
            }
        });
    }

    private void showAsrAnim() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                //在這里我們利用ValueAnimator.ofInt創(chuàng)建了一個(gè)值從textView的寬度到2的動(dòng)畫(huà),動(dòng)畫(huà)時(shí)長(zhǎng)是400ms,然后讓動(dòng)畫(huà)開(kāi)始
                //第一步:創(chuàng)建ValueAnimator實(shí)例
                ValueAnimator animator = ValueAnimator.ofInt(textView.getWidth(), 2);
                animator.setInterpolator(new LinearInterpolator());
                animator.setDuration(4000);

                //第二步:添加監(jiān)聽(tīng)
                animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        //獲取ValueAnimator在運(yùn)動(dòng)時(shí),當(dāng)前運(yùn)動(dòng)點(diǎn)的值
                        int width = (int) animation.getAnimatedValue();
                        changeLayout(width);
                        if (width == 2) {
                            textView.setText("");
                            textView.setVisibility(View.INVISIBLE);
                            ViewGroup.LayoutParams params = textView.getLayoutParams();
                            params.width = ViewGroup.LayoutParams.WRAP_CONTENT;
                            textView.setLayoutParams(params);
                        }
                    }
                });
                animator.start();
            }
        });
    }

    private void changeLayout(int width) {
        ViewGroup.LayoutParams params = textView.getLayoutParams();
        params.width = width;
        textView.setLayoutParams(params);
    }}
}

代碼中已經(jīng)有了注釋,創(chuàng)建一個(gè)ValueAnimator實(shí)例,添加監(jiān)聽(tīng),通過(guò)運(yùn)動(dòng)改變TextView的寬度,當(dāng)達(dá)到最小寬度2dp時(shí)將文本設(shè)置為空且不可見(jiàn),從而實(shí)現(xiàn)該功能。

到此,關(guān)于“如何用Android實(shí)現(xiàn)文字消除效果”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!

分享標(biāo)題:如何用Android實(shí)現(xiàn)文字消除效果-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://www.sd-ha.com/article38/jjhsp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、軟件開(kāi)發(fā)面包屑導(dǎo)航、App開(kāi)發(fā)、網(wǎng)頁(yè)設(shè)計(jì)公司網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管