Reputation: 3796
I am using RecyclerView with Implementing GridLayoutManager spanCount 3 and issue is background border displayed multiple time see screen shot and layout. But i need to single border shape with row item on this adapter. So share your experience and Thanks in Advance!
And this is RecyclerView.Adapter row xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linSubCat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@drawable/shape_sub_category"
android:gravity="center"
android:orientation="vertical"
android:padding="5dp">
<ImageView
android:id="@+id/subcategory_image_listview"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_gravity="center" />
<TextView
android:id="@+id/subcategory_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="3dp"
android:gravity="center|center_vertical"
android:padding="3dp"
android:textColor="@color/category_color" /></LinearLayout>
And Background border shape_sub_category.xml file.
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="@color/category_color" />
<solid android:color="@android:color/transparent" /></shape>
Upvotes: 1
Views: 880
Reputation: 3388
you can use ItemDecoration
https://developer.android.com/reference/android/support/v7/widget/DividerItemDecoration.html
https://gist.github.com/lapastillaroja/858caf1a82791b6c1a36
sample
int numColumns = 2;
Drawable horizontalDivider = ContextCompat.getDrawable(this, R.drawable.divider_horizontal);
Drawable verticalDivider = ContextCompat.getDrawable(this, R.drawable.divider_vertical);
recyclerView.setLayoutManager(new GridLayoutManager(..., numColumns));
recyclerView.addItemDecoration(new GridDividerItemDecoration(horizontalDivider, verticalDivider, numColumns));
Horizontal:divider_horizontal.xml
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#FF0000" />
Vertical:divider_vertical.xml
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#FF0000" />
Upvotes: 1