[英]Android: SwipeRefreshLayout containing Toolbar and RecyclerView
I have a SwipeRefreshLayout
, which contains a Toolbar
and RecyclerView
. 我有一个SwipeRefreshLayout
,其中包含一个Toolbar
和RecyclerView
。 When I scroll the RecyclerView
, the Toolbar
is hidden. 当我滚动RecyclerView
, Toolbar
被隐藏。 The problem is, that when refreshing the SwipeRefreshLayout
, it shows the spinner but it is actually hidden by the Toolbar
. 问题是,当刷新SwipeRefreshLayout
,它显示微调器,但实际上被Toolbar
隐藏。
The way I have my XML is this: 我拥有XML的方式是这样的:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/nearby_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primary"
android:minHeight="?attr/actionBarSize">
<followtheheat.ui.views.FthTextView
android:id="@+id/toolbar_title"
xmlns:fth="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/toolbar_text"
android:textColor="@android:color/white"
android:textSize="32sp"
android:textStyle="bold"
fth:font_family="osp_din"/>
</android.support.v7.widget.Toolbar>
Is there a way to do this in which the Toolbar isn't hidden when refreshing the RecyclerView, but it can still be hidden? 有没有一种方法可以使刷新RecyclerView时不隐藏工具栏,但仍然可以将其隐藏? I did it following this tutorial. 我是按照本教程进行的。
Thanks a lot in advance! 在此先多谢!
You could use a RelativeLayout to align the SwipeRefreshLayout below the Toolbar. 您可以使用RelativeLayout在工具栏下方对齐SwipeRefreshLayout。 This way neither the toolbar nor refresh indicator won't be drawn on top of each other. 这样,工具栏和刷新指示器都不会在彼此之上绘制。
If you can't use a RelativeLayout, just define the Toolbar in xml before the SwipeRefreshLayout. 如果您不能使用RelativeLayout,只需在SwipeRefreshLayout之前的xml中定义工具栏。 This way the refresh indicator will be drawn on top of the Toolbar. 这样,刷新指示器将绘制在工具栏的顶部。
Edit: If you want to use the second approach, on the showViews() method you should programmatically add a marginTop = ?attr/actionBarSize to the SwipeRefreshLayout, and remove it on hideView(). 编辑:如果要使用第二种方法,则应在showViews()方法上以编程方式将marginTop =?attr / actionBarSize添加到SwipeRefreshLayout中,并在hideView()上将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.