java - 我怎样才能使android-studio中的文本具有动画效果?

标签 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");

而不是只显示静态文本“准备文件”,我想知道如何让它显示类似移动点的东西,比如“准备文件......”然后“准备文件......”和“准备文件。 “并再次“准备文件...”然后“准备文件...”等等。

最佳答案

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

将其添加到依赖项

 compile 'pl.tajchert:waitingdots:0.2.0'

您可以使用这些方法。描述在链接中

关于java - 我怎样才能使android-studio中的文本具有动画效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33925293/

相关文章:

java - 如何在 avro 模式中创建包含字符串数组的对象?

java - Android ImageView 设置为本地 URL 不起作用?

java - 如何更改另一个 Activity 的主 xml 文件?

java - 使用多部分形式改造上传图像但不获取文件路径

android-studio - 如何将在 WSL2 中运行的 Android Studio 与连接的设备或在主机上运行的 Android 模拟器连接起来

android - 将 Eclipse 项目导入 Android Studio 时出现问题

java - 无法通过代理对象调用接口(interface)方法

java - YouTube 上传错误 - 上传失败 : Can't process file

java if 语句在 if(item instanceof nomclass) 中不起作用

android - 将 jar 库导入 android-studio