I'm trying to add a margin around my RecyclerView
whilst enusring it can scroll vertically but for some reason the scrollbar does not position itself at the end/right of the screen. Is this an issue specific to Android X?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/myLinearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/myRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
</LinearLayout>
Is this an issue specific to Android X?
Not really.
The issue here is you are specifying padding on the container of the RecyclerView.
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
This is because the rect used to draw the scrolls bars are limited to the rect where is drawn the RecyclerView. This is also the reason because the scroll bars restraint on the top.
Remove these and you are going to obtain the scroll bars positioned on the border of the screen.
Check also this related question