如何在coodinatorlayout设置中的appbar上添加swipetorefresh?
我在下面添加了我的xml。通过这种布局设置,我拉动刷新或刷卡以在appbar上刷新似乎不起作用。
是否可以实现这一点,还是我错过了什么?
swipetorefresh是否仅适用于recylerview?
协调员是否会导致问题?
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@color/dodger_blue"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="110dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|enterAlways">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="110dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<include
layout="@layout/layout_home_toolbar"
android:layout_width="match_parent"
android:layout_height="110dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.SwipeRefreshLayout
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/dummyData"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
编辑:
添加了请求的xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="110dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="110dp"
android:background="@color/dodger_blue"
android:orientation="vertical">
<com.test_rohan.homelayoutpoc.testMediumTextView
android:id="@+id/tv_hud_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:textColor="@color/snow"
android:textSize="16sp"
tools:text="test Care Team" />
<LinearLayout
android:id="@+id/layout_hud_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:baselineAligned="false"
android:orientation="horizontal">
<RelativeLayout
android:id="@+id/btn_one"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless">
<ImageView
android:id="@+id/iv_one"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_centerHorizontal="true"
android:background="@drawable/bg_profile_light"
android:contentDescription="@null"
android:padding="2dp"
tools:src="@drawable/default_group" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_one_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/iv_one"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:textColor="@color/snow"
android:textSize="10sp"
tools:ignore="SmallSp"
tools:text="Consult Coach" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_one_count"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginStart="-10dp"
android:layout_toEndOf="@id/iv_one"
android:background="@drawable/circular_red"
android:gravity="center"
android:minWidth="20dp"
android:padding="2dp"
android:textColor="#FFFFFF"
android:textSize="10sp"
android:visibility="gone"
tools:ignore="SmallSp"
tools:text="4" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/btn_two"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless">
<ImageView
android:id="@+id/iv_two"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_centerHorizontal="true"
android:background="@drawable/bg_profile_light"
android:contentDescription="@null"
android:padding="2dp"
tools:src="@drawable/default_group" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_two_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/iv_two"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:textColor="@color/snow"
android:textSize="10sp"
tools:ignore="SmallSp"
tools:text="Consult Expert" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_two_count"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginStart="-10dp"
android:layout_toEndOf="@id/iv_two"
android:background="@drawable/circular_red"
android:gravity="center"
android:minWidth="20dp"
android:padding="2dp"
android:textColor="#FFFFFF"
android:textSize="10sp"
android:visibility="gone"
tools:ignore="SmallSp"
tools:text="4" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/btn_three"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless">
<ImageView
android:id="@+id/iv_three"
android:layout_width="42dp"
android:layout_height="42dp"
android:layout_centerHorizontal="true"
android:background="@drawable/bg_profile_light"
android:contentDescription="@null"
android:padding="2dp"
tools:src="@drawable/default_group" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_three_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/iv_three"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:textColor="@color/snow"
android:textSize="10sp"
tools:ignore="SmallSp"
tools:text="Consult Doctor" />
<com.test_rohan.homelayoutpoc.testRegularTextView
android:id="@+id/tv_three_count"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginStart="-10dp"
android:layout_toEndOf="@id/iv_three"
android:background="@drawable/circular_red"
android:gravity="center"
android:minWidth="20dp"
android:padding="2dp"
android:textColor="#FFFFFF"
android:textSize="10sp"
android:visibility="gone"
tools:ignore="SmallSp"
tools:text="4" />
</RelativeLayout>
</LinearLayout>
<ImageView
android:id="@+id/iv_banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/dodger_blue"
android:contentDescription="@null"
android:visibility="gone" />
<ImageView
android:id="@+id/iv_default_banner"
android:layout_width="match_parent"
android:layout_height="@dimen/height_toolbar"
android:contentDescription="@null"
android:src="@drawable/default_hud_banner"
android:visibility="gone" />
答案 0 :(得分:0)
SwipeRefreshLayout
仅支持单个ListView
或GridView
孩子。
请参阅:https://developer.android.com/training/swipe/add-swipe-interface.html
答案 1 :(得分:0)
从SwipeRefreshLayout
移除CollapsingToolbarLayout
。所以应该看起来像这样
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/main.collapsing"
android:layout_width="match_parent"
android:layout_height="110dp"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|enterAlways">
<include
layout="@layout/layout_home_toolbar"
android:layout_width="match_parent"
android:layout_height="110dp" />
</android.support.design.widget.CollapsingToolbarLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/dummyData"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.SwipeRefreshLayout>
答案 2 :(得分:0)
因为滚动偏移尚未发送到父协调器布局。滚动偏移量由AppBarLayout本身计算,以进行偏移滚动。 如果要为AppBarLayout添加刷新,可以尝试使用仓库nestrefresh。使用RefreshBarLayout进行拉刷新。