How to position a view on top of another view in a RelativeLayout?
I have TextView
(denoted in green below) and a (denoted in LinearLayout
red below) in RelativeLayout
. I want to place a TextView on top LinearLayout
, for example:
However, I tried 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 application, it looks like this:
So, I want to know what I did wrong and how to fix it. Is there an xml attribute that I can use?
If you need more code to troubleshoot the problem, don't hesitate to tell me!
+3
source to share
4 answers
put a linear layout after the text view. put it like.
<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>
+3
source to share
Replacing your layout with the following should work.
<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>
0
source to share