考虑一下这个来自 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>
最佳答案
你试过抬高吗?问题可能是在 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/