2

I am using a line by using canvas in android as shown below.

canvas.drawLine(100,100,600, 600,mpaint);

I want this line to blink continuously. If anyone know about this, please help me...

sdabet
  • 18,360
  • 11
  • 89
  • 158
Binesh
  • 117
  • 3
  • 15
  • I don't know the answer. But, i've one suggestion for you. [Try like this](http://stackoverflow.com/a/9294196/940096) – Praveenkumar Aug 02 '12 at 12:04
  • I'm not sure about this, refer this link, here they worked with textview, if it possible means you can modify it http://android-vogue.blogspot.in/2011/05/how-to-blink-text-view-in-every-1.html – Aerrow Aug 02 '12 at 12:05
  • Please give more details about the context. Where do you get your canvas from ? – sdabet Aug 02 '12 at 12:07
  • Hi @Spk, Thanks for your reply.. I know about that u suggested.. I think its only for TextViews,Buttons etc.. Here I wants it for canvas... Could u please Help me, if you know about it... – Binesh Aug 02 '12 at 12:11
  • 1
    Oh Okay. [See this](http://stackoverflow.com/q/9947185/940096) – Praveenkumar Aug 02 '12 at 12:17
  • Thanks to all for ur replies.... – Binesh Aug 02 '12 at 12:41

1 Answers1

2

To make the line appear to blink you'll have to alternate between to different colors:

  • Draw red line
  • Draw blue line

You can simply do this with the following:

boolean blink = false;

// Define paint objects
Paint red = new Paint;
red.setColor(Color.RED);
Paint blue = new Paint;
blue.setColor(Color.BLUE);

In your update method you do this:

if(blink == false) {
blink = true;

}
else {
blink = false;
}

In your rendering method:

if(blink == true) {
canvas.drawLine(100,100,600, 600,red);
}
else {
canvas.drawLine(100,100,600, 600,blue);
}

I hope this helps!

Luke Taylor
  • 9,481
  • 13
  • 41
  • 73
  • 1
    `if (blink == false) blink = true...` You haven't considered `blink = !blink;`? canvas.drawLine can also be simplified to `canvas.drawLine(100,100,600, 600, blink ? red : blue);` – Simon Forsberg Sep 11 '13 at 17:09