将TextView放在ImageView前面

时间:2014-02-21 23:13:24

标签: java android eclipse

我正在寻找一种方法如何修复TextView,例如透明方块,就像我在Paint.net中所做的那样。所以TextView应该在透明方块(ImageView)的前面。它也应该伸展屏幕更大。

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

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

3 个答案:

答案 0 :(得分:6)

使用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>

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

答案 1 :(得分:4)

您可以使用RelativeLayout或FrameLayout。

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

您的textview将显示在ImageView上。

虽然注意到,RelativeLayout有双重征税权衡。每个度量和布局都会发生两次。

答案 2 :(得分:3)

只需在XML中从上到下对RelativeLayout中的项目进行排序,就会使每个项目与前面的其他项目相比向前移动。

相关问题