簡體   English   中英

如何以編程方式更改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上更改視圖的底部邊距並在其下方顯示進度條。 我看到這個這個問題,我也設法改變refreshLayout的利潤率,但RV成為切割的最后一個項目,我認為我必須要改變RV的利潤率也。 但是我無法獲得此視圖的布局參數。 對於refreshLayout,我使用了類似的方法:

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

而且效果很好,但是如何更改刷新布局中放置的recyclerview的邊距呢?

一條建議,而不是在到達滾動端時將進度條添加到recyclerview的最后一個位置上……這將確保顯示進度條。在recyclerview中很容易擁有多種類型的查看器這應該可以解決您的問題,而無需添加任何邊距/填充

RecyclerView最后一項削減了,這意味着,您只需要向RecyclerView的最后一個元素中添加填充,而不必為完整的RecyclerView提供填充。

您可以通過設置android:clipToPadding="false ”並將其paddingBottom等於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);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM