[英]Animation won't start
誰能看到我在做什么錯。 我創建一個動畫,並加載50幀。 嘗試啟動它,但是沒有任何反應。 初始開始幀在那里,但是什么也沒有發生。 我打印了動畫對象的幀數,顯示為50。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ShowCircle(50);
}
public void ShowCircle(final int percentage){
final ImageView ring = (ImageView)findViewById(R.id.ring);
animation = new AnimationDrawable();
ring.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
for(int i = 0; i != percentage; i++){
try
{
final int id = R.drawable.class.getField("rings_" + i).getInt(0);
animation.addFrame(getResources().getDrawable(id), 100);
}
catch(NoSuchFieldException n)
{
MessageBox(n.toString());
}
catch(IllegalAccessException e)
{
MessageBox(e.toString());
}
}
animation.setOneShot(false);
ring.setBackgroundDrawable(animation);
ring.post(new Starter());
MessageBox("# of frames: " + Integer.toString(animation.getNumberOfFrames()));
}
});
}
class Starter implements Runnable{
public void run(){
animation.start();
}
}
好的,愚蠢的我,ImageView有一個默認圖像。 動畫圖像僅設置為背景,這就是為什么它永遠不可見的原因...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.