我想显示缓冲文本,如缓冲..
我需要点不是静止的,即每2秒改变点数,使其变为'一个点,两个点,三个点,一个点等等。 我想知道最好的方法是什么。点应该在图像视图中吗?我应该有三张图片,每张图片都有一个特定的点数吗?或者有不同的方式来制作动画吗?
我有类似的东西使用处理程序长期回来。但在那种情况下,我知道结束时间。
以下是我之前的代码:
/**
* Use to show Loading... text while splash screen is loading. Here after each 350 milliseconds, i am adding
* a single dot(.) using thread and showing in the text view. And after reaching 3 dots, procedure is iterating itself again.
* This code will run till 3500 milliseconds.
*/
for (int i = 350; i <= SPLASHTIME; i = i + 350) {
final int j = i;
handler.postDelayed(new Runnable() {
public void run() {
if (j / 350 == 1 || j / 350 == 4 || j / 350 == 7
|| j / 350 == 10) {
tvLoadingdots.setText(".");
} else if (j / 350 == 2 || j / 350 == 5 || j / 350 == 8) {
tvLoadingdots.setText("..");
} else if (j / 350 == 3 || j / 350 == 6 || j / 350 == 9) {
tvLoadingdots.setText("...");
}
}
}, i);
}
任何人都可以告诉我最好的方法。
先谢谢。
答案 0 :(得分:-1)
我使用Text Switcher和runnable来解决这个问题
private void setupTextSwitcher() {
mLoadingChatBotTextSwitcher = (TextSwitcher)findViewById(R.id.chat_bot_loading_text_switcher);
mLoadingChatBotTextSwitcher.setInAnimation(this, android.R.anim.fade_in);
mLoadingChatBotTextSwitcher.setOutAnimation(this, android.R.anim.fade_out);
mLoadingChatBotTextSwitcher.addView(getTextSwitcherTextView());
mLoadingChatBotTextSwitcher.addView(getTextSwitcherTextView());
}
private TextView getTextSwitcherTextView() {
TextView textView = new TextView(this);
textView.setTextColor(getResources().getColor(R.color.birthday_white, null));
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 25);
return textView;
}
private void kickOffLoadingTextAnimation() {
if(mTextSwitchingHandler == null) {
mTextSwitchingHandler = new Handler(Looper.getMainLooper());
mTextSwitchingRunnable = new Runnable() {
int loadingIndex = 0;
@Override
public void run() {
switch(loadingIndex % 5) {
case 0:
changeLoadingMessage("Loading. ");
break;
case 1:
changeLoadingMessage("Loading.. ");
break;
case 2:
changeLoadingMessage("Loading... ");
break;
case 3:
changeLoadingMessage("Loading.... ");
break;
case 4:
changeLoadingMessage("Loading.....");
break;
}
loadingIndex++;
mTextSwitchingHandler.postDelayed(this, 500);
}
};
mTextSwitchingHandler.post(mTextSwitchingRunnable);
}
}