Questions tagged [android-paint]
68 questions
15
votes
1 answer
Is there a way to fall back to Typeface.SERIF in a StaticLayout?
I'm creating a custom View class that displays text using a StaticLayout with a custom typeface loaded from a .ttf asset file. The basic look of the typeface is a serif font and the TrueType properties in the font file indicate that it's serif.…

Ted Hopp
- 232,168
- 48
- 399
- 521
8
votes
1 answer
Display TextView with 2 separate colors using mask
I am trying to achieve an effect similar to this one:
What I am doing now:
public MaskedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setTextSize(25);
…

pat
- 1,005
- 4
- 12
- 29
7
votes
2 answers
Android Paint Object Memory Efficency
Is android.graphics.Paint memory heavy object? Which one is more efficient, to pass paint object refrence to classes that need to draw on canvas and set paint properties such as color, style, etc. in those classes, or create new Paint object…

Thracian
- 43,021
- 16
- 133
- 222
5
votes
0 answers
android - how to create shadow effect from zeplin
I have a project in zeplin and I have many views / layouts with
Shadows
outer
X 0dp Y 0dp
Blur 10dp Shadows 0dp
Color #000000
but I am not sure how to implement this in Android. How to specify blur shadow in Android along with a color?…

John61590
- 1,106
- 1
- 13
- 29
4
votes
1 answer
How to Draw Rounded Rectangle in API Level below 21 on a Canvas
I am creating a custom view by extending android.view.View.
Now, I need to draw a rounded rectangle on API level below 21. Android has a built in method name,drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint…

touhid udoy
- 4,005
- 2
- 18
- 31
4
votes
2 answers
The Base64 of Bitmaps created on two different android devices is not identical
I create a bitmap after doing some canvas and paint operations and then Base64 encode it to a string. When I repeat the process on a separate device and compare the base64 encoded strings returned by the two devices, they are different. Any ideas on…

Vinay Gaba
- 1,156
- 3
- 12
- 26
4
votes
1 answer
Android PathDashPathEffect: the path shape does not work for a straight line
I am trying to build a custom view that draws a line with diagonal stripes pattern. It should look similar to this:
I think using PathDashPathEffect should do, but when I set the path shape to be a straight line path, the view doesn't draw…

HeyThere
- 503
- 1
- 5
- 19
4
votes
1 answer
Cut region out of Bitmap with Path
I'm trying to get cut a jigsaw puzzle piece out of an image, creating a new Bitmap image. I'm using a Path object to do this. This is the current result.
And how I achived this
Path path = new Path();
// Multiple path methods to create…

dumazy
- 13,857
- 12
- 66
- 113
3
votes
1 answer
How to draw text in all caps on Canvas
I am drawing text on my Canvas using TextPaint and StaticLayout. However, I want my text to be drawn in capital letters. The suggestion online is to use toUpperCase() but that change does not reflect on the canvas.
This is my code:
public void…

Andros Adrianopolos
- 664
- 5
- 20
3
votes
1 answer
Set letter spacing to drawTextOnPath
I am using following code to make a spinner wheel.
@Override
public void onDraw(Canvas canvas)
{
super.onDraw(canvas);
for (int i = 0; i < segmentColors.length; i ++)
{
drawDataSet(canvas, i);
}
…

Muhammad Umar
- 11,391
- 21
- 91
- 193
3
votes
1 answer
Undo and Redo on canvas
I am developing drawing app, in which user can draw Shapes like Rectangle, circle etc. User can also make a free hand drawing(Pen).
I want to add undo, redo feature. I have searched and read most of SO answer for undo and redo, but all are related…

Rohan Patel
- 1,758
- 2
- 21
- 38
2
votes
0 answers
use custom font in paint object typeface field
I have a custom font defined in my style file:
I want to use it…

afgfdg
- 21
- 3
2
votes
2 answers
Can not set image resource of a custom imageview in Android
I have created a custom view project based on the lessons I have learned in this and this codelab.
In my project, I tried to draw not just on a view but on a custom ImageView. Therefore, I have created a custom ImageView and did all the steps as in…

ebeninki
- 909
- 1
- 12
- 34
2
votes
1 answer
How to make Paint.breakText respect word wrapping?
I want to calculate how many lines some text needs to fit into a fixed-width TextView. And I used Paint.breakText for this:
int maxWidth = WIDTH_IN_PIXELS;
int index = 0;
int linecnt = 0;
while (true) {
float[] measuredWidth = new float[1];
…

NeoWang
- 17,361
- 24
- 78
- 126
2
votes
1 answer
How to draw a path where the tail fades to transparent
I am creating a simple Android app within which there are particles which move across the screen.
These particles are currently drawn with a paint which has a LinearGradient shader applied. This allows the particle to nicely fade to transparent…

Alex
- 21
- 2