繁体   English   中英

Android:RelativeLayout上RecyclerView上方的TextView

[英]Android: TextView Above RecyclerView on RelativeLayout

好的,我需要一些帮助,因为这使我发疯。 我遍历了我在StackOverflow上可以找到的所有关于此的文章,并且我尝试了一切。 我应该提到的预览版看起来很完美。 但是,当我运行该应用程序时,TextView根本不存在。

我遵循了使RelativeLayout具有“可聚焦性”的建议。 我尝试了一种将TextView放在RecyclerView下的方法。 我尝试了类似“ LayoutAbove = @ recyclerviewid”的程序。

我已经尝试了我在StackOverflow上找到的所有内容,但没有任何效果,我不明白为什么它会在预览中起作用,但在应用程序中不起作用。 我一点都不明白。 无论如何! 编码:

<?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“”仅将“文本”发送到Android Studio。

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

这个问题并不像某些人想象的那么简单……它实际上与布局无关……而是代码中的错误。 我认为大多数人乍一看都忽略了这个问题,而没有真正去看问题可能是什么。 给我们所有人一个教训。 :)

像这样给TextView id属性

android:id="@+id/textView"

然后在其中添加此属性

android:layout_below="@+id/textView" 

在RecyclerView元素中

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

当您使用“工具”时,它只会在android studio中显示文本。

给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是从上到下“绘制”的,因此TextView将先绘制,然后recyclerView将绘制在TextView上方。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM