Как расположить вид поверх другого вида в RelativeLayout?



У меня есть TextView (обозначено зеленым цветом ниже) и LinearLayout (обозначено красным цветом ниже) в RelativeLayout. Я хочу расположить 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, который я могу использовать?

Если вам нужно больше кода, чтобы определить проблему, не стесняйтесь сказать это я!

612   4  

4 ответов:

Поместите линейный макет после просмотра текста. поставьте его так.

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

Comments

    Ничего не найдено.