[英]Align the top of a View to the bottom of another view in a RelativeLayout
[英]How to position a view on top of another view in RelativeLayout?
我在RelativeLayout
有一个TextView
(在下面用绿色表示)和一个LinearLayout
(在下面用红色表示)。 我想将TextView放在LinearLayout
顶部,如下所示:
但是,我试过这个:
<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"/>
但是,当我运行应用程序时,它是这样的:
所以我想知道我做错了什么以及如何解决它。 我可以使用xml属性吗?
如果您需要更多代码来识别问题,请随时告诉我!
像TextView
一样将LinearLayout
放在TextView
之后:
<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>
在Java中,您可以通过text1.bringToFront();
在LinearLayout
添加以下行:
<LinearLayout
...
android:layout_below:"@+id/text1">
</LinearLayout>
用下面的替换你的布局应该有效。
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignLeft="@id/linear_layout"
android:text="my text"
android:textSize="10pt"
android:id="@+id/text1"/>
<LinearLayout
android:id="@+id/linearlayout"
android:layout_below="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linear_layout">
<!--some other views-->
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.