SwipeRefreshLayout 隐藏 RecyclerView 的上半部分?

SwipeRefreshLayout hides RecyclerView's upper part?

我是 android 的初学者,我不知道为什么会这样。 在没有 SwipeRefreshLayout 的情况下,RecyclerView 是完全可见的,但是在使用 SwipeRefreshLayout 的情况下,不会显示第一个项目。

也许它在工具栏下面? (隐藏物品是存在的,我多方查过)

<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/swipe_layout">

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/MainRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>

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

列表:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="8dip"
    android:paddingBottom="8dip"
    android:paddingLeft="16dip"
    android:paddingRight="16dip"
    android:weightSum="10"
    android:gravity="center">


    <ImageView
        android:id="@+id/CharacterItemRankImageView"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_weight="0"
        android:src="@drawable/challengemode_medal_bronze"/>

    <TextView android:id="@+id/CharacterItemNameTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="3.5"
        tools:text="Name"/>


    <TextView android:id="@+id/CharacterItemPointsTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAlignment="center"
        android:layout_weight="6"
        tools:text="Points"/>

    <ImageButton
        android:id="@+id/CharacterItemRemoveButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_weight="0.5"
        android:src="@drawable/ic_delete_grey600_48dp"
        android:scaleType="fitXY" style="@style/Widget.AppCompat.Button.Borderless" />

</LinearLayout>

我猜您正在使用 CoordinatorLayout 作为视图的根。在这种情况下,发生的情况是工具栏被 RecyclerView 的第一项隐藏了。

要解决此问题,您只需将布局行为添加到 SwipeRefreshLayout 并从 RecyclerView 中删除。

<android.support.v4.widget.SwipeRefreshLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/MainRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

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