Reputation: 4119
Is that possible to add a dynamic text to drawable or bitmap in android? im trying do something like get some text dynamically and put that text into an image. Or at least i want to give a illusion to the user that the text is inside that image.
Upvotes: 1
Views: 2706
Reputation: 2606
I know you have found the solution but some people may be interested in this new way of setting Imageview with Text
Here is my Solution:-
Bitmap bitmap = BitmapFactory.decodeResource(
getResources(), com.cinchvalet.app.client.R.drawable.slider_pop_counter);
Bitmap bmp = bitmap.copy(Bitmap.Config.ARGB_8888, true);
Canvas c = new Canvas(bmp);
String text = "Your text";
Paint p = new Paint();
p.setTypeface(Typeface.DEFAULT_BOLD);
p.setTextSize(35);
p.setColor(getResources().getColor(com.cinchvalet.app.client.R.color.Black));
int width = (int) p.measureText(text);
int yPos = (int) ((c.getHeight() / 2)
- ((p.descent() + p.ascent()) / 2) - 10);
c.drawText(text, (bmp.getWidth() - width) / 2, yPos, p);
-on your bitmap Image Draw Text On bitmap and then you can set Bitmap to your Imageview
-THanks!
Upvotes: 1
Reputation: 47809
Have you considered simply overlaying a TextView
over the ImageView
using a relative layout?
Upvotes: 0