How to set border for android recyclerview grid layout.
HomepageActivity.java
recyclerView = findViewById(R.id.recyclerView);
imageAdapter = new ImageAdapter(this);
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(new DividerItemDecoration(this,
DividerItemDecoration.HORIZONTAL))
recyclerView.addItemDecoration(new DividerItemDecoration(this,
DividerItemDecoration.VERTICAL))
recyclerView.setLayoutManager(new GridLayoutManager(HomepageActivity.this,2));
recyclerView.setAdapter(imageAdapter);
single_item_homepage.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:selectableItemBackground"
android:orientation="vertical"
android:padding="@dimen/fifteen_dp">
<ImageView
android:id="@+id/ivGraphItemThumb"
android:layout_width="match_parent"
android:layout_height="125dp"
tools:src="@drawable/ic_recent_exce" />
<TextView
android:id="@+id/tvMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="@color/black"
android:textSize="@dimen/fifteen_sp"
tools:text="Item 1" />
</LinearLayout>