我正在开发一个android应用程序。在这我有像一个图像, 如何在android中的图像的顶部放置文本?
这里,什么是我的要求是,
我需要这里面小黑盒子里显示的文字。 我不知道从哪里开始或寻找什么。 如果有人能给我一些提示,请告诉我。 在此先感谢...
我正在开发一个android应用程序。在这我有像一个图像, 如何在android中的图像的顶部放置文本?
这里,什么是我的要求是,
我需要这里面小黑盒子里显示的文字。 我不知道从哪里开始或寻找什么。 如果有人能给我一些提示,请告诉我。 在此先感谢...
首先,您需要一个相对的布局,将它放入图像视图和文本视图中。 然后
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
尝试从左侧或右侧,这样你的文本将在黑box.Hope设置这将有助于提高利润率。
您可以使用画布在图像上绘制文字。
Bitmap bmp; // your image I don't how you got this but if in asset or in drawable get into the bitmap object
Canvas canvas = new Canvas(bmp);
canvas.drawText("Text", 100, 100, new Paint());
另一种方法是使用布局
<RelativeLayout>
<ImageView android:src="your image">
<TextView android:text="Your text"/>
</RelativeLayout>
这将覆盖在imageview的
TextView的不要ü要显示这样
,那么你必须使用框架布局...看下面的代码..
XML:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/layer13"
android:layout_gravity="center" />
<TextView
android:id="@+id/textView1"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Janmejoy"
android:textColor="#000000"
android:layout_gravity="center"
android:textSize="15dp" />
</FrameLayout>
</LinearLayout>
或者你可以设置你的文本视图的背景。你不需要额外的图像视图。这只适用于您希望在背景中显示纯色的情况,如您在要求中所示。
你能提供一个图像的最终结果,即它会看起来像文本一样吗? – ninetwozero
你可以采取relativelayout并采取edittext并将此图像设置为relativelayout背景,并将edittext背景设置为透明。 –