首页 > 解决方案 > 水平回收站视图中的不可见项目

问题描述

我正在使用 GridLayoutManager 在水平方向的 recyclerview 中显示一些图像。但是图像在回收站视图中是不可见的。当我在空白处点击时,它会在另一个活动中显示图像,但它们在回收站视图中是不可见的。我试过 VERTICAL 并且它们非常好并且可见。

这是我的片段 xml:

<RelativeLayout>
    <ImageView
        android:id="@+id/imageView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:rotation="180"
        android:scaleType="centerCrop"
        app:srcCompat="@drawable/page_start" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:visibility="visible"
        android:layout_height="match_parent" />

</RelativeLayout>

片段.java:

RecyclerView rv;
    List<Cards> cardsList;
    Context context;

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        context = getActivity();
        View rootView = inflater.inflate(R.layout.fragment_cards, container, false);

        readJson readJson = new readJson(context);
        cardsList = readJson.getcardsList();

        rv = rootView.findViewById(R.id.rv);

        rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false));
        rv.setAdapter(new CardsListAdapter(empty, context));

标签: javaandroidandroid-recyclerviewgridlayoutmanager

解决方案


"rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, false));"

使用下面的行

rv.setLayoutManager(new GridLayoutManager(context, 3, GridLayoutManager.HORIZONTAL, true));

或者

rv.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, true));

推荐阅读