• Advertisement
Sign in to follow this  

Bitmap only drawn once not drawn in updated co ordinates

This topic is 1865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.
[b]MainActivity.java[/b]

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;
}

[b] BitmapView.java[/b]
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();

}




}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement