如何使画布眨眼和不变的自动旋转? [英] How to make a canvas blink and invariant to auto-rotate?

查看:175
本文介绍了如何使画布眨眼和不变的自动旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使为Android定制的地图应用程序。我有地图的图像,我想给用户的立场作为一个闪烁的矩形。这里是code我写了到目前为止:

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?

推荐答案

有关旋转,你可以通过将其禁用安卓screenOrientation =画像在活动部位你的表现。 对于眨眼,你可以有一个这样的计时器:

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:

Long timer = System.currentTimeMillis();

draw()
{
----
if(System.currentTimeMillis()>timer+100)
{
timer=System.currentTimeMillis();
    canvas.drawRect(19, 11, 30, 19, paint);
}

您可以更改100到你认为合适的。另外一个问题你是从你给我们画仅调用一次。

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.

这篇关于如何使画布眨眼和不变的自动旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆