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:

enter image description here

How to make a normal indent in a textView?

  • Try to remove layout_alignParentEnd - Dimanoid
  • @Dimanoid did not help - iamtihonov
  • and if android: layout_margin in the text is replaced with android: padding? reproduced at any image size? and with the usual imageview? - Dimanoid
  • @Dimanoid yes, really android: padding works. As I myself did not think to install it. Thank. I wonder why the margin does not work. With the usual ImageView, the error remains. - iamtihonov
  • @Dimanoid and can write the answer below, I will mark it. - iamtihonov

2 answers 2

Try android:layout_margin in the text to replace with android:padding .

The thought android:layout_alignParentBottom not very clear description android:layout_alignParentBottom

If true, it makes a match. Accommodates bottom margin.

Honestly I didn’t really understand what they meant. But since padding not mentioned, it was worth a try. Well that worked. :)

    I would advise you to put the following android.support.v7.widget.CardView in your .xml file, with about the following parameters

      `android:id="@+id/card_view" android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="100dp" android:layout_margin="25dp" card_view:cardCornerRadius="15dp">` 

    before that, of course, don't forget to import into build.gradle> dependencies> compile 'com.android.support:cardview-v7:24.0.0'

    and then play with the values)