首页 > 解决方案 > 如何在 ScrollView 上重叠 RecyclerView

问题描述

正如我下面的代码,我试图将 Recyclerview 重叠在 ScrollView 上。我看到很少有 java 使用的教程,但我想用 xml 代码创建。我不确定我是否做得对。附件是我想创建的,请作为您的参考。

在此处输入图像描述

<?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="wrap_content" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="#759AF8">

    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:orientation="vertical" 
        android:layout_marginTop="50dp">
        
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Trend" 
            android:textStyle="bold" 
            android:textSize="24sp"
            android:layout_gravity="center" />
        
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="What's trending in Korea"
            android:textSize="18sp"
            android:layout_gravity="center" />
      </LinearLayout>

      <ScrollView 
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/recipe_background"
          android:layout_marginTop="200dp"
          android:padding="20dp">

          <androidx.recyclerview.widget.RecyclerView
              android:id="@+id/recycler"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center_horizontal"
              android:elevation="7dp"
              app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
              android:orientation="vertical" />
      </ScrollView>

</RelativeLayout>

标签: androidandroid-recyclerview

解决方案


推荐阅读