我想做以下 - 动画数字序列更改,我正在使用TextSwitcher.我有用户得分,它会不时变化.有没有办法对此更改进行动画处理,以便将此数字从其当前值缓慢增加到其结果值?像http://josheinstein.com/blog/index.php/2010/02/silverlight-animated-turbotax-number-display/,但对于Android.
小智 7
我一直在找同样的,有朋友帮我,这是一份工作样本.希望对你有效.
-Raj
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;
public class TimerUpdateAnimatorActivity extends Activity {
private static final int toValue = 20;
private static final int fromValue = 0;
private static final int FRAME_TIME_MS = 100;
private static final String KEY = "i";
private TextView animatedText;
boolean isRunning = false;
// background updating
Handler handler = new Handler() {
public void handleMessage(Message msg) {
try {
int i= msg.getData().getInt(KEY);
animatedText.setText(""+i);
} catch (Exception err) {
}
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
animatedText = (TextView) findViewById(R.id.animatedText);
}
public void onStart() {
super.onStart();
Thread background = new Thread(new Runnable() {
public void run() {
try {
for (int i = fromValue; i <= toValue && isRunning; i++) {
Thread.sleep(FRAME_TIME_MS);
Bundle data= new Bundle();
data.putInt(KEY, i);
Message message = handler.obtainMessage();
message.setData(data);
handler.sendMessage(message);
}
}
catch (Throwable t) {
}
}
});
isRunning = true;
background.start();
}
public void onStop() {
super.onStop();
isRunning = false;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3423 次 |
| 最近记录: |