My RecyclerView item layout:
<ImageView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f2f2f2"
android:scaleType="centerCrop"
tools:src="@color/black_alpha_60"
android:padding="10dp"/>
When I changed ListView to RecyclerView, I found that the padding missing on Android 4.1.2 Device, but it works well on Android 7.1, I tried to set padding in Java code (onBildViewHolder) like this:
ImageView iv = (ImageView) holder.itemView;
if (iv.getPaddingLeft() == 0) {
int p = AppUtils.dp2px(iv.getContext(), 10);
iv.setPadding(p, p, p, p);
}
And it still not working. Is there any capability solution to resolve this problem for all android platform devices excepting change padding to margin? Thank you.
PS: RecyclerView version: 25.3.1
Update: The iv.setPadding(p,p,p,p) works when I add android:cropToPadding="true" to the ImageView. But prefer to use android:padding="10" to declare the padding than using setPadding API.