1

I have such layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".jobAGENT.JobsList">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="75dp"
        android:gravity="center_horizontal"
        android:text="@string/no_jobs"
        android:textSize="32sp"
        android:textStyle="italic"
        android:visibility="gone" />

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/refresh_t"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginStart="5dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="5dp"
        android:background="@color/white">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/job_list_t"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp" />

    </android.support.v4.widget.SwipeRefreshLayout>

    <ProgressBar
        android:id="@+id/loader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:visibility="gone" />


</RelativeLayout>

I would like to change margin of RecyclerView and SwipeRefreshLayout programmatically when I reach some conditions. For example, at my onScrollListener when my list reaches its end I would like to change bottom margin of my views and show progressbar below it. I saw this and this questions and I have also managed to change margin of refreshLayout but the last item of RV become cut and I think that I have to change margin of RV also. But I can't get layout params of this view. For refreshLayout I used smth like that:

val param = refreshLayout.layoutParams as RelativeLayout.LayoutParams
param.setMargins(5,10,5,150)
refreshLayout.layoutParams = param

and it works good, but how I can also change margin of recyclerview which is placed inside refresh layout?

Andrew
  • 1,947
  • 2
  • 23
  • 61

3 Answers3

3

Last item in your RecyclerView cuts, meaning, you'll have to add padding only to the last element of RecyclerView, instead of giving padding to complete RecyclerView.

You can do that by setting android:clipToPadding="false", and giving it paddingBottom equal to the height of your SwipeRefreshLayout.

You can do that as follows:

<android.support.v7.widget.RecyclerView
    android:paddingBottom="56dp"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Adjust the paddingBottom as per your need.

Vedprakash Wagh
  • 3,595
  • 3
  • 12
  • 33
1

A suggestion, instead add the progress bar as an item of the recyclerview at the last position when you reach the scroll end... this will ensure that the bar is displayed.. It is easy enough to have multiple types of viewholders in a recyclerview and this should solve your issue without needing to add any margin/padding

Kushan
  • 5,855
  • 3
  • 31
  • 45
0

try this..

RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
            RecyclerView.LayoutParams.MATCH_PARENT,
            RecyclerView.LayoutParams.MATCH_PARENT
    );
    params.setMargins(50, 50, 50, 50);
    jobListT.setLayoutParams(params);
Prachi Singh
  • 564
  • 3
  • 8