Android RecyclerView LayoutManager - 第一项为一列,其余项目作为第二列中的行

问题描述 投票:0回答:1

是否可以使用一些布局管理器来布局 RecyclerView 项目,如图所示? 第一列是第一项,其余项目作为第二列中的行?

android android-recyclerview layout-manager
1个回答
0
投票

不幸的是,对于 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
中。

© www.soinside.com 2019 - 2024. All rights reserved.