如何在RelativeLayout中将视图放置在另一个视图之上? [英] How to position a view on top of another view in RelativeLayout?
本文介绍了如何在RelativeLayout中将视图放置在另一个视图之上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在RelativeLayout
中有一个TextView
(下面用绿色表示)和一个LinearLayout
(下面用红色表示).我想将TextView放在LinearLayout
的顶部,如下所示:
I have a TextView
(indicated in green below) and a LinearLayout
(indicated in red below) in a RelativeLayout
. I want to position the TextView on top of the LinearLayout
, like this:
但是,我尝试过:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linear_layout">
<!--some other views-->
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" <!--this because the textview is the topmost view on the screen so I tried to use this-->
android:layout_alignLeft="@id/linear_layout"
android:text="my text"
android:textSize="10pt"
android:id="@+id/text1"/>
但是,当我运行该应用程序时,它是这样的:
However, when I run the app, it is like this:
所以我想知道我做错了什么以及如何解决.我可以使用xml属性吗?
So I want to know what did I do wrong and how to fix it. Is there an xml attribute that I can use?
如果您需要更多代码来识别问题,请随时告诉我!
If you need more code to identify the problem, feel free to tell me!
推荐答案
将LinearLayout
放在TextView
之后,如下所示:
Put your LinearLayout
after TextView
like this:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" <!-- this because the textview is the topmost view on the screen so I tried to use this -->
android:text="my text"
android:textSize="10pt"
android:id="@+id/text1" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:orientation="vertical"
android:id="@+id/linear_layout">
<!-- some other views -->
</LinearLayout>
这篇关于如何在RelativeLayout中将视图放置在另一个视图之上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文