我发现了这个post,我试图让这个代码对我有用,但我遇到了问题。
package com.example.converter;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
public class Savannah extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_savannah);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_savannah, menu);
return true;
}
public boolean onTouch(View v, MotionEvent event) {
final int DELAY = 100;
if(event.getAction() == MotionEvent.ACTION_UP) {
RelativeLayout savannah = (RelativeLayout) findViewById(R.layout.activity_savannah);
ColorDrawable f = new ColorDrawable(0xff00ff00);
ColorDrawable f2 = new ColorDrawable(0xffff0000);
ColorDrawable f3 = new ColorDrawable(0xff0000ff);
ColorDrawable f4 = new ColorDrawable(0xff0000ff);
AnimationDrawable a = new AnimationDrawable();
a.addFrame(f, DELAY);
a.addFrame(f2, DELAY);
a.addFrame(f3, DELAY);
a.addFrame(f4, DELAY);
a.setOneShot(false);
savannah.setBackgroundDrawable(a); // This method is deprecated in API 16
// savannah.setBackground(a); // Use this method if you're using API 16
a.start();
}
return true;
}
}
所以这是我的非工作代码,它不会标记错误,但它不会像它应该的那样频闪。有谁能告诉我这有什么不对吗?
12-19 10:43:00.239: D/dalvikvm(15327): GC_EXTERNAL_ALLOC freed 351K, 47% free 3735K/6983K, external 1818K/1848K, paused 43ms
12-19 10:43:00.289: D/dalvikvm(1735): GC_FOR_MALLOC freed 159K, 49% free 3427K/6663K, external 0K/0K, paused 31ms
12-19 10:43:02.139: I/ActivityManager(1109): Starting: Intent { cmp=com.example.converter/.Savannah } from pid 20056
12-19 10:43:02.399: I/ActivityManager(1109): Displayed com.example.converter/.Savannah: +254ms
12-19 10:43:02.709: D/dalvikvm(1735): GC_FOR_MALLOC freed 140K, 49% free 3416K/6663K, external 0K/0K, paused 54ms
12-19 10:43:02.759: D/dalvikvm(1735): GC_FOR_MALLOC freed 145K, 49% free 3419K/6663K, external 0K/0K, paused 17ms
12-19 10:43:05.429: D/dalvikvm(1735): GC_FOR_MALLOC freed 167K, 49% free 3428K/6663K, external 0K/0K, paused 28ms
12-19 10:43:08.589: D/dalvikvm(15327): GC_EXPLICIT freed 113K, 47% free 3728K/6983K, external 1336K/1848K, paused 76ms
12-19 10:43:10.529: D/dalvikvm(1735): GC_FOR_MALLOC freed 160K, 49% free 3428K/6663K, external 0K/0K, paused 32ms
12-19 10:43:12.709: D/dalvikvm(1735): GC_FOR_MALLOC freed 126K, 49% free 3416K/6663K, external 0K/0K, paused 57ms
12-19 10:43:12.749: D/dalvikvm(1735): GC_FOR_MALLOC freed 146K, 49% free 3419K/6663K, external 0K/0K, paused 19ms
12-19 10:43:12.969: I/ActivityManager(1109): Starting: Intent { cmp=com.example.converter/.Savannah } from pid 20056
12-19 10:43:13.209: I/ActivityManager(1109): Displayed com.example.converter/.Savannah: +233ms
12-19 10:43:16.229: D/dalvikvm(1735): GC_FOR_MALLOC freed 165K, 49% free 3426K/6663K, external 0K/0K, paused 50ms
12-19 10:43:21.849: D/dalvikvm(1735): GC_FOR_MALLOC freed 160K, 49% free 3427K/6663K, external 0K/0K, paused 47ms
12-19 10:43:21.879: D/dalvikvm(1735): GC_FOR_MALLOC freed 129K, 49% free 3427K/6663K, external 0K/0K, paused 18ms
12-19 10:43:22.739: D/dalvikvm(1735): GC_FOR_MALLOC freed 156K, 49% free 3419K/6663K, external 0K/0K, paused 35ms