如何以编程方式更改 swipeRefreshlayout 的底部边距?

How to change bottom margin of swipeRefreshlayout programmatically?

我有这样的布局:

<?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>

我想在达到某些条件时以编程方式更改 RecyclerView 和 SwipeRefreshLayout 的边距。例如,在我的 onScrollListener 列表到达末尾时,我想更改视图的底部边距并在其下方显示进度条。我看到了 this and 个问题,我还设法更改了 refreshLayout 的边距,但 RV 的最后一项被剪切了,我认为我也必须更改 RV 的边距。但我无法获得此视图的布局参数。对于 refreshLayout,我使用了这样的方法:

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

效果很好,但我如何更改位于刷新布局内的 recyclerview 的边距?

一个建议,当你到达滚动结束时,在最后一个位置添加进度条作为recyclerview的一个项目...这样可以确保进度条显示..很容易有多种类型recyclerview 中的查看器,这应该可以解决您的问题,而无需添加任何 margin/padding

RecyclerView 削减中的最后一项,这意味着,您只需向 RecyclerView 的最后一个元素添加填充,而不是为完成 RecyclerView 添加填充。

您可以通过设置 android:clipToPadding="false" 并将其 paddingBottom 设置为等于您 SwipeRefreshLayout 的高度来实现。

您可以按如下方式进行:

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

根据需要调整 paddingBottom

试试这个..

RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(
            RecyclerView.LayoutParams.MATCH_PARENT,
            RecyclerView.LayoutParams.MATCH_PARENT
    );
    params.setMargins(50, 50, 50, 50);
    jobListT.setLayoutParams(params);