Centerally对准了ImageView的文字在Android的线性布局 [英] Centerally aligned text over ImageView in android Linear Layout
本文介绍了Centerally对准了ImageView的文字在Android的线性布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何显示与线性布局的Android ImageView的文本。我发现很多例子为此目的而堆栈溢出,但所有都是相对布局,框架布局但我没有得到它的线性布局。
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 getting it in Linear Layout.
我已经尝试了的android:文本=我的文字
但它不工作
I have tried for android:text="My Text"
But its not working.
请给我建议,如果可能这样做。如果是这样如何能不能做到。
Please suggest me if its possible to do so. If so how can it be done.
<ImageView
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:background="@drawable/iosbutton" />
这是附在本的ImageView上,我想显示在中心的文本图像。
This is the Image attached to this ImageView on which I want to display text in the center.
推荐答案
试试这个
使用这个方法
public BitmapDrawable writeOnDrawable(int drawableId, String text){
Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.BLACK);
paint.setTextSize(20);
Canvas canvas = new Canvas(bm);
canvas.drawText(text, 0, bm.getHeight()/2, paint);
return new BitmapDrawable(bm);
}
这样调用
ImageView image=(ImageView)findViewById(R.id.imageView1);
image.setImageDrawable(writeOnDrawable(R.drawable.ic_launcher,"Hello"));
这篇关于Centerally对准了ImageView的文字在Android的线性布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文