android - RecyclerView 内容落后而不是上面的 TextView

标签 android xml android-layout kotlin android-recyclerview

考虑一下这个来自 Material Design 的关于拖放项目的视频:

Material design reordering list

在视频中,您会看到一个 RecyclerView,在其上方是一个带有文本“播放列表”的 TextView。当该行被向上拖动时,您会看到它越过播放列表。

在我的代码中,该行位于 Textview 后面。我已将 RecyclerView 的 layout_height 设置为 match_parent。我使用了 FrameLayout 并将 TextView 放在 RecyclerView 下方。为什么不过去呢?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layoutRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/general_margin"
        android:text="@string/activity_bible_order_explanation"
        android:layout_gravity="start|top" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:layout_marginTop="96dp"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</FrameLayout>

enter image description here

最佳答案

你试过抬高吗?问题可能是在 z 轴上 TextView 高于 RecyclerView。尝试添加 android:elevation="10dp"或更高...像这样:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/layoutRoot"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="@dimen/general_margin"
        android:text="@string/activity_bible_order_explanation"
        android:layout_gravity="start|top" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="10dp" (if it doesn't work try maybe higher elevation, 20dp etc.)
        android:background="@android:color/transparent"
        android:layout_marginTop="96dp"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

</FrameLayout>

希望它对你有用(:让我知道!

关于android - RecyclerView 内容落后而不是上面的 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59577409/

相关文章:

java - 创建按钮并分离那里的功能android

java - 在一个测试中我可以找到一个 xml,在另一个测试中我找不到

java - 如何根据正则表达式更改 XML 与文本(字符数据)的匹配

android - 嵌套约束布局android的性能

android - 我如何从自定义 View 中知道父填充?

java - 带有类的 Swift 文件到 Android studio

Kotlin 中的 Android 房间错误

ruby 中的xml差异?

Android BaseAdapter Pinterest 风格

android - (Android) 线程化的 httpClient 任务,不阻塞 UI?