提问者:小点点

如何用水平滚动完成这个RecyclerView?


将布局管理器设置为此代码将创建所需的格式,但它是垂直滚动的。

recyclerView.SetLayoutManager(new GridLayoutManager(Context, 2, GridLayoutManager.Vertical, false));

将LayoutManager设置为此代码会创建不正确的格式,但它是水平滚动的。

recyclerView.SetLayoutManager(new GridLayoutManager(Context, 2, GridLayoutManager.Horizontal, false));

我的问题是,如何创建两个并排且可以水平滚动的 CardView 格式?

以下是CardView XML,以备需要:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/cardView"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="10dp">
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#FF0000">
  </RelativeLayout>
</android.support.v7.widget.CardView>

共1个答案

匿名用户

尝试使用水平方向的LinearLayoutManager:

LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);

如果您想同时显示两张卡片,请将它们的宽度设置为屏幕大小的一半。