不幸的是,对于 RecyclerView 设置,这是不可能的。但你可以实现上面的图像如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal"
tools:context=".MainActivity2">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:layout_weight="1"
app:cardBackgroundColor="#673AB7"
app:cardCornerRadius="10dp"
app:cardElevation="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndtOf="@+id/cardView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
在您的
RecyclerView
中,您可以创建一个 CustomAdapter
,将您的条目显示为 CardView Rows
。然后您确定内容的平均值并将其显示在左侧。这也更加可靠,因为您可以确定 CardView
的内容,而无需连接到 RecyclerView
。如果您想让所有内容都可滚动,您可以将 LinearLayout 包装在 ScrollView
中。