Loop/Graphic problem

Discussion in 'Android Lounge' started by Burning Desire, Nov 29, 2010.

  1. Burning Desire

    Burning Desire New Member
    5

    Nov 29, 2010
    1
    0
    5
    Hello, I am new to android but not to programming. And the code below makes the icon.png that is available by default in android, go across the screen or at least it is supposed to. This doesn't work. Can anyone help?


    package com.android.test;
    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.os.Bundle;


    import android.view.View;
    import android.view.Window;

    public class Android extends Activity {
    int x,y=10;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(new Panel(this));
    }

    class Panel extends View {
    public Panel(Context context) {
    super(context);
    }

    @Override
    public void onDraw(Canvas canvas) {
    Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
    canvas.drawColor(Color.BLACK);
    int n=1;
    while (n==1){
    try {
    Thread.sleep(30);
    } catch (InterruptedException e) { }
    canvas.drawBitmap(_scratch, x, y, null);
    x+=2;
    y+=2;

    canvas.drawBitmap(_scratch, x, y, null);
    }
    }
    }
    }
     

    Advertisement

Share This Page

Loading...