如何让android-studio中的文本动画?

时间:2015-11-25 19:53:12

标签: java android-studio

例如,如果我在TextView中显示文本“正在上传”,我现在希望它将文本显示为“正在上传...”,并且要删除的3个点再次显示,就像处理某事而不仅仅是静态文本。

我在MainActivity onTouch事件中有这个:

@Override
        public boolean onTouchEvent(MotionEvent event)
        {
            float eventX = event.getX();
            float eventY = event.getY();

            float lastdownx = 0;
            float lastdowny = 0;

            switch (event.getAction())
            {
                case MotionEvent.ACTION_DOWN:
                    lastdownx = eventX;
                    lastdowny = eventY;

                    Thread t = new Thread(new Runnable()
                    {
                        @Override
                        public void run()
                        {
                            byte[] response = null;
                            if (connectedtoipsuccess == true)
                            {

                                if (is_start == true)
                                {
                                    uploadTimerBool = true;
                                    timers.StartTimer(timerValueRecord, "Recording Time: ");
                                    response = Get(iptouse + "start");
                                    is_start = false;
                                } else
                                {
                                    timers.StopTimer(timerValueRecord);
                                    textforthespeacch = "Recording stopped and preparing the file to be shared on youtube";
                                    MainActivity.this.runOnUiThread(new Runnable()
                                    {
                                        @Override
                                        public void run()
                                        {
                                            status1.setText("Preparing the file");
                                        }
                                    });
                                    MainActivity.this.initTTS();
                                    response = Get(iptouse + "stop");
                                    is_start = true;
                                    startuploadstatusthread = true;
                                    servercheckCounter = 0;
                                }
                                if (response != null)
                                {
                                    try
                                    {
                                        a = new String(response, "UTF-8");

                                        MainActivity.this.runOnUiThread(new Runnable()
                                        {
                                            @Override
                                            public void run()
                                            {
                                                if (a.equals("Recording started"))
                                                {
                                                    status1.setText("Recording");
                                                }
                                                if (a.equals("Recording stopped and preparing the file to be shared on youtube"))
                                                {
                                                    status1.setText("Recording Stopped");
                                                }
                                            }
                                        });
                                        textforthespeacch = a;
                                        MainActivity.this.initTTS();
                                    } catch (UnsupportedEncodingException e)
                                    {
                                        e.printStackTrace();
                                    }
                                    Logger.getLogger("MainActivity(inside thread)").info(a);
                                }
                            }
                        }
                    });
                    t.start();
                    return true;
                case MotionEvent.ACTION_MOVE:
                    break;
                case MotionEvent.ACTION_UP:
                    break;
                default:
                    return false;
            }
            return true;
        }

这一行:

status1.setText("Preparing the file");

相反只显示静态文本“准备文件”我想知道如何使它显示诸如“准备文件......”之类的移动点,然后“准备文件......”和“准备文件”。 “再次“准备文件......”然后“准备文件......”等等。

2 个答案:

答案 0 :(得分:2)

使用这个很棒的库,正是您正在寻找的: https://github.com/tajchert/WaitingDots

将此添加到依赖项

 compile 'pl.tajchert:waitingdots:0.2.0'

你可以使用这个方法。描述在链接

答案 1 :(得分:1)

Handler handler = new Handler();

for (int i = 100; i <= 3500; i=i+100) {
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            if(i%300 == 0){
                textView.setText("Uploading.");
            }else if(i%200 == 0){
                textView.setText("Uploading..");
            }else if(i%100 == 0){
                textView.setText("Uploading...");
            }
        }
    }, i);
}