Bitmap only drawn once not drawn in updated co ordinates

Started by
-1 comments, last by VIJAY007 11 years, 5 months ago
Hi all

am trying to draw bitmap and redraw it in updated coorinates.but it is only drawn once.
what to do.

Code for your reference.
MainActivity.java

import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.app.Activity;
import android.view.Display;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
public class MainActivity extends Activity {
private PowerManager mPowerManager;
//private WindowManager mWindowManager;
//private Display mDisplay;
private WakeLock mWakeLock;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new BitmapView(this));
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Create a bright wake lock
mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, getClass()
.getName());
}

@Override
protected void onResume() {
super.onResume();
/*
* when the activity is resumed, we acquire a wake-lock so that the
* screen stays on, since the user will likely not be fiddling with the
* screen or buttons.
*/

// Start the simulation

}
@Override
protected void onPause() {
super.onPause();
/*
* When the activity is paused, we make sure to stop the simulation,
* release our sensor resources and wake locks
*/
// Stop the simulation
// mSimulationView.stopSimulation();
// and release our wake-lock
//mWakeLock.release();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}

BitmapView.java
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
class BitmapView extends View {
int posx=10;
int posy=10;
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.obstacle);

public BitmapView(Context context) {
super(context);
}
public void update()
{


if(posx>getWidth())
{
posx=-17;
}
else
{
posx=+17;
}

}
@Override
public void onDraw(Canvas canvas)
{
//super.onDraw(canvas);
canvas.drawBitmap(bmp, posx, posy, null);
update();
invalidate();

}




}

This topic is closed to new replies.

Advertisement