Centerally Aligned Text Over Imageview In Android Linear Layout
How to display text on android ImageView with Linear Layout. I found many examples on stack overflow for this purpose but all are for Relative Layout, Frame Layout But I am not get
Solution 1:
Try this
Use this method
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmapbm= BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paintpaint=newPaint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
Canvascanvas=newCanvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
returnnewBitmapDrawable(bm);
}
call like this
ImageView image=(ImageView)findViewById(R.id.imageView1);
image.setImageDrawable(writeOnDrawable(R.drawable.ic_launcher,"Hello"));
Solution 2:
Does it have to be an ImageView?
<TextView
android:id="@+id/share_button"
android:layout_width="fill_parent"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="2"
android:text="text"
android:gravity="center"
android:background="@drawable/iosbutton" />
Post a Comment for "Centerally Aligned Text Over Imageview In Android Linear Layout"