【问题标题】:SwipeRefresh Layout is covering the recycleviewSwipeRefreshLayout 覆盖recyclerview
【发布时间】:2020-02-22 17:23:25
【问题描述】:

我在实现刷新布局时遇到问题。它涵盖了一切。 我不知道是什么问题,但我尝试从片段更改为活动,没有帮助

这是我的代码:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="@color/background">




      <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/background">

        <androidx.core.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

                <TextView
                    android:id="@+id/topheadelines"
                    android:textColor="@color/colorTextTitle"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:text="Top Headlines"
                    android:fontFamily="sans-serif-light"
                    android:textSize="17sp"
                    android:layout_marginLeft="16dp"
                    android:layout_marginRight="16dp"
                    android:layout_marginTop="10dp"
                    android:visibility="invisible"/>

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:scrollbars="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
                  </androidx.recyclerview.widget.RecyclerView>

               </LinearLayout>

           </androidx.core.widget.NestedScrollView>

        </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
   </androidx.coordinatorlayout.widget.CoordinatorLayout>

另外,我确实认为工具栏有问题,而是放置了一个操作栏(没有帮助)

更新:

这是我的 swiperefresh 布局的功能,以防万一:

@Override
    public void onRefresh() {
        LoadJson("");
    }

    private void OnLoadingSwipeRefresh(final String keyword){

        swipeRefreshLayout.post(
                new Runnable() {
                    @Override
                    public void run() {
                        LoadJson(keyword);
                    }
                }

        );
    }

【问题讨论】:

    标签: java android xml android-recyclerview swiperefreshlayout


    【解决方案1】:

    我发现了我的错误。它不在我的布局中。它在适配器的代码中。

    @Override
    public int getItemCount() {
        return articles.size();
    
    }
    

    返回 0;是默认设置的,这是我的错误。 我知道这很愚蠢,但以防万一像我这样的人跳过该错误并且不知道原因。

    【讨论】:

      猜你喜欢
      • 2014-09-30
      • 2015-10-31
      • 1970-01-01
      • 2017-01-06
      • 2017-01-02
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多