我有一个带有图像的imageView,我想在该图像上放置一个文本。我怎样才能做到这一点呢?
发布于 2011-11-25 23:23:01
这就是我是如何做到的,它的工作方式完全符合您在RelativeLayout中的要求:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativelayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myImageSouce" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/myImageView"
android:layout_alignTop="@id/myImageView"
android:layout_alignRight="@id/myImageView"
android:layout_alignBottom="@id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
发布于 2012-10-26 22:56:53
你可能想从不同的方面考虑:在背景上有一个可绘制的TextView似乎更容易:
<TextView
android:id="@+id/text"
android:background="@drawable/rounded_rectangle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</TextView>
发布于 2011-03-09 16:14:19
您希望使用FrameLayout或合并布局来实现这一点。Android开发指南在这里有一个很好的例子:Android Layout Tricks #3: Optimize by merging。
https://stackoverflow.com/questions/5242951
复制相似问题