I am trying to make a custom map application for Android. I have the map as an image and I want to show the user’s position as a blinking rectangle. Here is the code I have written so far:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView resultImageHolder = (ImageView) findViewById(R.id.test_image);
layout = (FrameLayout) findViewById(R.id.frame_layout);
draw();
}
private void draw() {
int width = 200;
int height = 200;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
bitmap.eraseColor(Color.TRANSPARENT);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
Canvas canvas = new Canvas(bitmap);
canvas.drawRect(19, 11, 30, 19, paint);
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
layout.addView(imageView);
}
Now I need to make the canvas blink and also make the canvas stay in its correct position even if the screen auto-rotates. How can I achieve both things?
For the rotation you could disable it by putting
android:screenOrientation="portrait"in your Activity parts of your manifest.For the blink you could have a timer like this:
You can change the 100 to what you see fit. Another issue you have is from what you showed us draw is only called once.