Android: RelativeLayout 上 RecyclerView 上方的 TextView

Android: TextView Above RecyclerView on RelativeLayout

好的,我需要一些帮助,因为这让我抓狂。我已经遍历了在 Whosebug 上可以找到的所有 post,并且我已经尝试了所有方法。预览,我应该提一下,看起来很完美。但是当我 运行 应用程序时,TextView 根本不存在。

我听从了制作 RelativeLayout 的建议 "focusable." 我尝试了将 TextView 放在 RecyclerView 下的建议。我尝试了类似 "LayoutAbove=@recyclerviewid".

的那个

我确实尝试了我在 Whosebug 上找到的所有内容,但没有任何效果,而且我不明白为什么它在预览中有效,但在应用程序中却无效。我完全不明白。反正!代码:

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

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        tools:text="EVENTS"
        android:textStyle="bold"
        android:paddingTop="10dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="60dp"
        android:id="@+id/events_view"
        >

    </android.support.v7.widget.RecyclerView>



</RelativeLayout>

编辑: 根据 TakeInfo 的回答......(这非常重要,我不知道......)上面的代码不起作用的唯一原因是因为我使用了 "tools:text="EVENTS"",这意味着 "text" 只会发送到 Android Studio。

我当然会把这个问题留在这里,因为我确信我不是唯一不知道这一点的人。

这道题并不像有些人想的那么简单……其实跟版面无关……而是代码错误。我认为大多数人第一眼就忽略了这个问题,而没有真正了解问题所在。给我们大家上了一课。 :)

尝试 android:text="EVENTS" 而不是 tools:text="EVENTS"

当您使用 'tools' 时,它只会在 android 工作室中显示文本。

给 textview 一个 id 并将你的 recyclerview 对齐到 textview 下面。

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="EVENTS"
        android:textStyle="bold"
        android:paddingTop="10dp"
        android:paddingLeft="8dp"
        android:paddingRight="8dp"
        />

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/textView"
        android:paddingTop="60dp"
        android:id="@+id/events_view"/>

很简单,用垂直方向的LinearLayout就可以了。这样您的所有视图都会显示在另一个视图下方。

在您的 xml 中,交换 TextView 和 RecyclerView 的位置。

xml从上到下是"drawn",所以先画TextView再画recyclerView在TextView上面

切换它们将使 TextView 在回收器视图之后绘制。

像这样给 TextView id 属性

android:id="@+id/textView"

然后在里面加上这个属性

android:layout_below="@+id/textView" 

在 RecyclerView 元素中