gpt4 book ai didi

android - 不断地为 Loading... textview 设置动画

转载 作者:行者123 更新时间:2023-11-29 14:36:05 26 4
gpt4 key购买 nike

我正在尝试为“正在加载...” TextView 的三个点设置动画,如下所示,

Handler handler = new Handler();

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

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

问题是, 1. 在对话框可见之前,我无法无限地为其设置动画。 2. 无法降低三点动画的速度,

我怎样才能解决这个问题

最佳答案

例子:

 final Handler handler = new Handler();
Runnable runnable = new Runnable() {

int count = 0;

@Override
public void run() {
count++;

if (count == 1)
{
textView.setText("Loading.");
}
else if (count == 2)
{
textView.setText("Loading..");
}
else if (count == 3)
{
textView.setText("Loading...");
}

if (count == 3)
count = 0;

handler.postDelayed(this, 2 * 1000);
}
};
handler.postDelayed(runnable, 1 * 1000);

关于android - 不断地为 Loading... textview 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39136999/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com