我想,创建一个GIF动画视图..
当我尝试在模拟器中运行的后续代码一切工作正常。 但是,当我在现实智能手机尝试运行,没有任何反应..
我的看法:
public class GIFView extends View {
private Movie mMovie;
private long movieStart;
public GIFView(Context context) {
super(context);
initializeView();
}
public GIFView(Context context, AttributeSet attrs) {
super(context, attrs);
initializeView();
}
public GIFView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initializeView();
}
private void initializeView() {
InputStream is = getContext().getResources().openRawResource(
R.drawable.cookies2);
mMovie = Movie.decodeStream(is);
}
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
if (movieStart == 0) {
movieStart = (int) now;
}
if (mMovie != null) {
int relTime = (int) ((now - movieStart) % mMovie.duration());
mMovie.setTime(relTime);
mMovie.draw(canvas, getWidth() - mMovie.width(), getHeight()
- mMovie.height());
this.invalidate();
}
}}
我的活动:
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GIFView gifView = new GIFView(this);
setContentView(gifView);
}}
我的智能手机屏幕截图: 我的模拟器截图:
为什么我的应用程序不会在智能手机上运行?