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