如何将 TextView above-left 定位在另一个元素上?

How to position TextView above-left on another element?

我有一个片段,其中包括一个Textview 和一个ListView。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".uiFragments.WikiFragment">

    <RelativeLayout
        android:id="@+id/tablayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingTop="50dp">

        <TextView
            android:id="@+id/ampel_weiss"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_marginTop="5dp"
            android:layout_marginRight="5dp"
            android:gravity="center"
            android:textSize="40sp"
            android:text="TEST"
            android:textColor="#00000C"
            android:background="@color/ampelWE20"
            android:layout_alignParentLeft="true"/>

        <ListView
            android:id="@+id/custom_list"
            android:layout_height="100dp"
            android:layout_width="1000dp"
            android:listSelector="@drawable/list_color_selector"
            android:background="@drawable/listview_border"
            android:layout_centerHorizontal="true"/>

    </RelativeLayout>


</FrameLayout>

目前,它看起来像下图:

你可以看到左边的"Text"。 我想将文本放在 "Listview" 上方,但它不应该在它的中心,而是在 ListView 的左侧,如下图所示:

我是这个主题的新手,很乐意提供帮助,因为据我所知,重力与线性布局中的不同。

多谢指教!

编辑: 当我使用下面评论中的解决方案时,我现在得到下面这张图片。

试试这个 使用 LinearLayout 而不是 RelativeLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tablayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="50dp">


<TextView
    android:id="@+id/ampel_weiss"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:layout_gravity="left|center_horizontal|center_vertical"
    android:background="@color/colorPrimary"
    android:gravity="left"
    android:text="TEST"
    android:textColor="#00000C"
    android:textSize="40sp" />

<ListView
    android:id="@+id/custom_list"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_gravity="center_horizontal" />


</LinearLayout>

尝试以下操作:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:id="@+id/tablayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingTop="50dp">

    <TextView
        android:id="@+id/ampel_weiss"
        android:layout_width="1000dp"
        android:layout_height="60dp"
        android:layout_marginTop="5dp"
        android:layout_marginStart="5dp"
        android:text="TE"
        android:textSize="40sp"
        android:textColor="#00000C"
        android:layout_alignParentTop="true"
        android:background="@android:color/white"
        android:layout_centerHorizontal="true" />

    <ListView
        android:id="@+id/custom_list"
        android:layout_height="100dp"
        android:layout_width="1000dp"
        android:layout_below="@+id/ampel_weiss"
        android:layout_centerHorizontal="true">
    </ListView>


</RelativeLayout>


</FrameLayout>

输出: