Hello.

There is a CardView , inside of which is a TextView . The CardView itself CardView wrapped in a ScrollView :

 <?xml version="1.0" encoding="utf-8"?> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <android.support.v7.widget.CardView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginRight="50dp" android:layout_marginLeft="50dp"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorAccent" android:text="здесь большой текст"/> </android.support.v7.widget.CardView> </ScrollView> 

As you can see from the markup code, the fields on the left and right have CardView added to CardView - and they really are and are displayed correctly.

You need to add top and bottom fields to CardView .

Adding android:layout_marginTop to CardView leads to the addition of a field at the top, but in this case ScrollView does not scroll to the end.

Adding android:layout_marginBottom to CardView does not make any changes at all.

Tell me, please, how to correctly add these fields.

Ps. In fact, the markup is much more complicated, it is only a minimal reproducible example.

  • one
    Can try padding and clopToPadding="false" in ScrollView ? - lllyct
  • @lllyct, In principle, if CardView add layout_marginLeft and layout_marginRight , and to android:clipToPadding="false" to ScrollView android:clipToPadding="false" , paddingTop and paddingBottom , then you almost get what you need. But in this case, the scrollbar starts from the end of the upper indent and ends at the beginning of the lower one, but I would like it to be equal in height to both the paddings. - Burence
  • It seems that ScrollView has attributes about the location of the scrollbars, but it's easier to do as advised by Yuri and add an additional FrameLayout. - lllyct

1 answer 1

You need an additional container.

Those. put something on ScrollView, for example FrameLayout, to which you need to set the necessary paddings, and then place CardView in it. Or assign margins already for CardView.

  • one
    It seems that I tried this option, but for some reason it did not work, now I tried it - everything is ok. Mystic :) Thank you! - Burence