Android:包含 Toolbar 和 RecyclerView 的 SwipeRefreshLayout
Android: SwipeRefreshLayout containing Toolbar and RecyclerView
我有一个 SwipeRefreshLayout
,其中包含一个 Toolbar
和 RecyclerView
。
当我滚动 RecyclerView
时,Toolbar
被隐藏。问题是,当刷新 SwipeRefreshLayout
时,它会显示微调器,但实际上它被 Toolbar
.
隐藏了
我的 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>
有没有办法做到刷新RecyclerView时Toolbar不隐藏,但仍然可以隐藏?
我是按照 this 教程做的。
非常感谢!
您可以使用 RelativeLayout 将 SwipeRefreshLayout 对齐到工具栏下方。这样工具栏和刷新指示器就不会相互重叠绘制。
如果不能使用RelativeLayout,只需在SwipeRefreshLayout 之前的xml 中定义Toolbar。这样,刷新指示器将绘制在工具栏的顶部。
编辑:
如果你想使用第二种方法,在 showViews() 方法上,你应该以编程方式将 marginTop = ?attr/actionBarSize 添加到 SwipeRefreshLayout,并在 hideView().
上删除它
我有一个 SwipeRefreshLayout
,其中包含一个 Toolbar
和 RecyclerView
。
当我滚动 RecyclerView
时,Toolbar
被隐藏。问题是,当刷新 SwipeRefreshLayout
时,它会显示微调器,但实际上它被 Toolbar
.
我的 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>
有没有办法做到刷新RecyclerView时Toolbar不隐藏,但仍然可以隐藏? 我是按照 this 教程做的。
非常感谢!
您可以使用 RelativeLayout 将 SwipeRefreshLayout 对齐到工具栏下方。这样工具栏和刷新指示器就不会相互重叠绘制。
如果不能使用RelativeLayout,只需在SwipeRefreshLayout 之前的xml 中定义Toolbar。这样,刷新指示器将绘制在工具栏的顶部。
编辑: 如果你想使用第二种方法,在 showViews() 方法上,你应该以编程方式将 marginTop = ?attr/actionBarSize 添加到 SwipeRefreshLayout,并在 hideView().
上删除它