简体   繁体   中英

Put a TextView in front of a ImageView

Im searching a way how to fix a TextView on a ,for example, transparent square like in the Picture I did in Paint.net .So the TextView should in front of the transparent square (ImageView).Also it should stretch when the screen is bigger.

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

How can I solve the problem ? Thanks !

Use a 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>

Alternatively, you could do something similar with a relative layout.

You can use RelativeLayout or FrameLayout for that.

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

Your textview will appear on ImageView.

Although note that, RelativeLayout has double taxation tradeoff. Each measure and layout happens twice.

简单地在XML中从上到下排序RelativeLayout中的项目将使每个项目与其上方的其他项目相比向前移动。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM