Reputation: 4585
i want to remove divider (space) between items of RecyclerView
So try to set background
of item view and RecyclerView
to White
,but it doesn't works
how to fix it ?
Item View 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>
Activity 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"/>
Activity
Class :
rv_categories.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
rv_categories.setItemAnimator(new DefaultItemAnimator());
Upvotes: 17
Views: 32207
Reputation: 1619
For some reason the other answers didn't work for me but this workaround did:
for (int i = 0; i < recyclerView.getItemDecorationCount(); i++) {
if (recyclerView.getItemDecorationAt(i) instanceof DividerItemDecoration)
recyclerView.removeItemDecorationAt(i);
}
Upvotes: 6
Reputation: 298
Add
android:divider="@null"
android:dividerHeight="0dp"
to recyclerView xml.
Upvotes: -2
Reputation: 2454
Dont use below line of code in your code, its solve the iisue
groceryRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), LinearLayoutManager.HORIZONTAL));
or
recycle.addItemDecoration(new DividerItemDecoration(context, 0));
Upvotes: 1
Reputation: 355
First define your RecyclerView :
RecyclerView recycle =(RecyclerView) findViewById(R.id.recyclerView);
and in your activity use this method:
recycle.addItemDecoration(new DividerItemDecoration(context, 0));
Upvotes: 24
Reputation: 6315
You can use DividerItemDecoration
class and override its onDraw
method to do nothing like so:
mRecyclerView.addItemDecoration(new DividerItemDecoration(mContext, LinearLayoutManager.VERTICAL) {
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
// Do not draw the divider
}
});
Upvotes: 9