【发布时间】:2018-09-20 22:36:43
【问题描述】:
如何在 coodinatorlayout 设置内的应用栏上添加 swipetorefresh?
我在下面添加了我的 xml。使用此布局设置,我在应用栏上拉动刷新或滑动刷新似乎不起作用。
是否有可能实现这一点,或者我错过了什么?
swipetorefresh 是否仅适用于 recylerview?
coordinatorlayour 是否造成了问题?
<?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" />
【问题讨论】:
-
也发布“layout_home_toolbar”的 xml
-
添加了请求的xml
-
移除应用栏布局内的 SwipeRefreshLayout。后一种是正确的。
Does swipetorefresh work only with a recylerview? Answer is No : The SwipeRefreshLayout should be used whenever the user can refresh the contents of a view via a vertical swipe gesture and can only support one direct child -
@Sanny 。是的,我将 swiperefresh 移至包含的布局。但它仍然不起作用。只有当下面的 recyclerview 滚动了一点,然后在快速返回 appbar 时,我才能刷新。如果下面的recyclerview根本没有滚动,滑动刷新不起作用
-
@RohanM 还检查了 collaspingToolbar 的使用情况。 >CollapsingToolbarLayout 是 {@link Toolbar} 的包装器,它实现了可折叠的应用栏。 * 它被设计为用作 {@link AppBarLayout} 的直接子级。
标签: android android-coordinatorlayout android-appbarlayout swiperefreshlayout