There is a RecyclerView , this is how one item looks like (item.xml):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background"> <com.company.testapp10.ProportionalImageView android:id="@+id/imageView" android:layout_width="110dp" android:layout_height="wrap_content" android:src="@drawable/image" android:adjustViewBounds="true" /> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="text" android:textSize="20sp" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" android:layout_margin="20dp"/> </RelativeLayout> The image is large and shrinks to 110dp in width while respecting proportions, here’s the ProportionalImageView code:
public class ProportionalImageView extends ImageView { public ProportionalImageView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { Drawable d = getDrawable(); if (d != null) { int w = MeasureSpec.getSize(widthMeasureSpec); int h = (w * d.getIntrinsicHeight()) / d.getIntrinsicWidth(); setMeasuredDimension(w, h); ViewParent viewParent = getParent(); if(viewParent instanceof RelativeLayout) { RelativeLayout parentLayout = (RelativeLayout) viewParent; parentLayout.getLayoutParams().height = h; } } else { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } } If item.xml is not used in the list (the first view in the figure), the lower indent of the textView displayed correctly, but if it is inside the list (the subsequent views in the figure), then it simply does not exist. After scrolling through the list, indents appear. Here's what it looks like:
How to make a normal indent in a textView?
