SwipeRefreshView,CollapsingToolbar和RecyclerView

时间:2015-09-23 13:13:10

标签: android toolbar swiperefreshlayout appbar android-collapsingtoolbarlayout

enter image description here

刷新指示器不会显示在顶部。相反,它显示在Recycler视图的顶部。但是,我需要它显示在Gmail,Google Plus等顶部。

继承布局代码和MainActivity

$formData['name']

MainActivity.java

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:fitsSystemWindows="true">


<android.support.design.widget.AppBarLayout
    android:id="@+id/bar"
    android:layout_width="match_parent"
    android:layout_height="252dp"
    android:fitsSystemWindows="true">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:collapsedTitleTextAppearance="@style/CollapsedAppBar"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleMarginBottom="32dp"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/random"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.7" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/anim_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>

</android.support.design.widget.AppBarLayout>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/contentView"
    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/scrollableview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="152dp"
    android:layout_height="152dp"
    android:background="@android:color/transparent"
    android:clickable="false"
    android:scaleType="fitXY"
    app:borderWidth="0dp"
    app:layout_anchor="@id/bar"
    app:layout_anchorGravity="bottom|center" />
</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:0)

尝试此代码,必须在ActionBar底部显示指示符

int[] actionBarSizeAttr = new int[] { android.R.attr.actionBarSize };
TypedValue typedValue = new TypedValue();
TypedArray a = context.obtainStyledAttributes(typedValue.data, actionBarSizeAttr);
int actionBarSize = a.getDimensionPixelSize(0, 100);
a.recycle();
swipeRef.setProgressViewOffset(false, 0, actionBarSize);
swipeRef.setProgressViewEndTarget(false, actionBarSize);