将文本视图放在图像视图的前面



我正在寻找一种方法,例如,在透明正方形上修复TextView,就像我在 Paint.net 中所做的图片一样。因此,TextView应该在透明正方形(ImageView)的前面。当屏幕较大时,它也应该伸展。

http://www7.pic-upload.de/22.02.14/24vtze5ulxc2.png

我该如何解决问题?谢谢!

使用 FrameLayout

<FrameLayout
    android:layout_height="wrap_content"
    android:layout_width="wrap_content">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/semi_transparent_background"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="This is my text."/>
</FrameLayout>

或者,您可以使用相对布局执行类似的操作。

您可以使用 RelativeLayout 或 FrameLayout。

<FrameLayout>
   <ImageView>
   <TextView>
</FrameLayout>

您的文本视图将显示在图像视图上。

但请注意,相对布局具有双重征税权衡。每个度量和布局发生两次。

简单地在

XML 中从上到下对 RelativeLayout 中的项目进行排序,将使每个项目依次移动到前面,而不是上面的其他项目。

最新更新