【发布时间】:2019-06-05 05:37:01
【问题描述】:
我有这样的布局:
<?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 和this 的问题,我也设法改变了 refreshLayout 的边距,但是 RV 的最后一项被削减了,我认为我也必须改变 RV 的边距。但我无法获得此视图的布局参数。对于 refreshLayout 我使用了这样的东西:
val param = refreshLayout.layoutParams as RelativeLayout.LayoutParams
param.setMargins(5,10,5,150)
refreshLayout.layoutParams = param
而且效果很好,但是我怎样才能改变放置在刷新布局内的 recyclerview 的边距?
【问题讨论】:
标签: android android-layout margins