我正在尝试,创建一个带有动画 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);
}}
我的智能手机截图: 我的模拟器截图:
为什么我的应用无法在智能手机上运行?