Elias Dolinsek
Elias Dolinsek

Reputation: 749

Android Margin and Padding aren't working for RecyclerViews inside ScrollViews

When I place a RecyclerView as a child of a ScrollView, marginBottom and paddingBottom doesn't work. Setting these values for the parent LinearLayout doesn't affect anything either. It seems that the ScrollView doesn't scroll to the bottom because the ScrollBar doesn't reach the bottom. How can I fix this bug?

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<!--To avoid scroll view from scrolling to the bottom automatically-->
<View android:layout_width="match_parent" android:id="@+id/focus_view" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true"><requestFocus/></View>

<ScrollView
    android:id="@+id/sv_categories_statistics"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="10">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_margin="4dp">

        <LinearLayout
            android:id="@+id/ll_categories_statistics_filters_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="4dp">

            <LinearLayout
                android:id="@+id/ll_categories_statistics_select_date_fragment_container"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@drawable/border_primary_light"
                android:padding="4dp"
                android:layout_marginEnd="4dp"/>

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:background="@drawable/border_accent"
                android:padding="4dp">

                <Spinner
                    android:id="@+id/spn_categories_statistics_bill_type"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"/>

            </LinearLayout>
        </LinearLayout>

        <com.github.mikephil.charting.charts.PieChart
            android:id="@+id/pc_categories_statistics"
            android:layout_width="match_parent"
            android:layout_height="325dp"
            android:layout_margin="4dp"/>

    <fragment
        android:id="@+id/fgm_categories_statistics_not_enough_data"
        class="com.dolinsek.elias.cashcockpit.NotEnoughDataFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="24dp"
        app:text="@string/label_not_enough_data_for_statistic"
        android:layout_marginStart="4dp"
        android:layout_marginEnd="4dp"
        android:layout_marginBottom="8dp"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_categories_statistics"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </LinearLayout>
</ScrollView>

Example

Upvotes: 3

Views: 707

Answers (1)

prashant17
prashant17

Reputation: 1550

Have you tried clipToPadding

 <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_categories_statistics"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="50dp"
            android:clipToPadding="false"/>

Upvotes: 4

Related Questions