Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if `onDraw` is called in preview mode

In my custom-drawn view I use the Canvas.drawPaint(Paint) method. But the preview in Android Studio displays this message:

The graphics preview in the layout editor may not be accurate: 
    - Canvas.drawPaint is not supported

It's easy to replace drawPaint with drawRect, but the javadoc to drawPaint says: This is equivalent (but faster) to drawing an infinitely large rectangle with the specified paint.

My question is: can I check, if I'm drawing in preview mode, and conditionally use either method? Or some other workaround to make preview working and keep the performance?

like image 915
Oliv Avatar asked Sep 18 '25 08:09

Oliv


1 Answers

You can use View's built-in isInEditMode() function as documented here: http://developer.android.com/reference/android/view/View.html#isInEditMode%28%29

You can also find other methods in this thread: Custom Android Views in Eclipse Visual Editor

Good luck!

like image 196
Or Polaczek Avatar answered Sep 21 '25 00:09

Or Polaczek