如何在Android中删除Recyclerview项目之间的分隔线 [英] how to remove divider between items of Recyclerview in android

查看:105
本文介绍了如何在Android中删除Recyclerview项目之间的分隔线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除RecyclerView项之间的分隔线(空格)

i want to remove divider (space) between items of RecyclerView

因此,请尝试将商品视图的背景 RecyclerView 设置为 White ,但这不起作用如何解决?

So try to set background of item view and RecyclerView to White,but it doesn't works how to fix it ?

项目视图 XML :

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@android:color/white"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="match_parent">
    <LinearLayout
        android:background="@android:color/white"
        android:paddingLeft="@dimen/footer_item_padding"
        android:paddingRight="@dimen/footer_item_padding"
        android:orientation="vertical"
        android:gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/img_avatar_category_item_adapter"
            android:contentDescription="@string/app_name"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:layout_width="@dimen/image_width_category_adapter"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</android.support.v7.widget.CardView>

活动XML:

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_categories_main_activity"
            android:background="@android:color/white"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

活动类别:

    rv_categories.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    rv_categories.setItemAnimator(new DefaultItemAnimator());

推荐答案

首先定义您的RecyclerView:

First define your RecyclerView :

RecyclerView recycle =(RecyclerView)findViewById(R.id.recyclerView);

RecyclerView recycle =(RecyclerView) findViewById(R.id.recyclerView);

在您的活动中使用此方法:

and in your activity use this method:

recycle.addItemDecoration(new DividerItemDecoration(context, 0));

这篇关于如何在Android中删除Recyclerview项目之间的分隔线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆