RecyclerView内CoordinatorLayout,AppBarLayout滚动发行
我在片段此XML代码:RecyclerView内CoordinatorLayout,AppBarLayout滚动发行
<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:id="@+id/coordinatorLayout" android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme"
app:elevation="0dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_scrollFlags="scroll"
android:id="@+id/collapsingToolbarLayout"
app:statusBarScrim="@color/bestColor">
<LinearLayout></LinearLayout> <!--this elements hide then appbar is collapsed-->
</android.support.design.widget.CollapsingToolbarLayout>
<LinearLayout>
<ImageButton>
android:id="@+id/profile_header_trophies"
</ImageButton><!-- this elements like a tab,visible if appbar collapsed-->
</LinearLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/profile_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
中的Java类
在项目设置ClickListener:
@OnClick(R.id.profile_header_trophies)
public void profile_header_trophies_clicked() {
if (myProfile != null) {
appBarLayout.setExpanded(false, false);
if (myProfile.getBests().size() == 0) {
profile_recyclerView.smoothScrollToPosition(3);
} else {
profile_recyclerView.smoothScrollToPosition(2 + 20);
}
}
当我点击的ImageButton,我RecyclerView滚动到位置,一切看起来都很好。 但是,如果我把AppBarLayout部分(ImageButton)上的可见(粘)顶部,并拖动到底部的手指我有一个不好的滚动。 我的appbar开始展开,而我的Recycler顶部有一些元素(它们在滚动时隐藏)。
我觉得这个问题是设置behavoir。因为如果我先滚动回收站,AppBar不会开始扩展,而Recycler不是最丰富的元素。
感谢您的回答。
一次滚动不良发生在我身上,发生这种情况是因为我在另一个RecyclerView
内使用RecyclerView
。
所以,当我试图滚动主RecyclerView
内容时,它给了我这个问题。
要解决的问题,我已将此添加RecyclerView
:
recyclerView.setNestedScrollingEnabled(false);
对于XML这样做,你可以使用:
android:nestedScrollingEnabled="false"
这不起作用 –
更糟的是,这实际上完全是倒退。你不应该有这个,它会阻止预期的行为 –
它可以是棘手,还有你需要有几件事情为了这个工作。
您应该在CollapsingToolbarLayout
中使用app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
而不是scroll
。
不清楚标签或按钮在XML布局中的位置,但如果它们应该保留在屏幕上,那么您需要pin
这些标签或按钮,因此您可以使用app:layout_collapseMode="pin"
作为该元素。也许这是在LinearLayout
或ImageView
?
如果LinearLayout
拥有其他东西,那么你应该添加一些滚动标志,如果它应该滚动屏幕,最好是app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
。
最后,请确保您的不是禁用RecyclerView中的嵌套滚动。
不适合我。 – NehaK
这一点,你告诉它“合并”的RecyclerView的滚动与其父的滚动
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
如果我很好理解,你想有以下滚动行为
:
- 如果您通过触摸外部RecyclerView进行滚动,它将折叠AppBar
- 如果您通过触摸它内部进行滚动,它会忽略RecyclerView的滚动并折叠AppBar,并且一旦AppBar为colla在RecyclerView内滚动
请问您是否确认这是您想要的行为?
在这种情况下,你可以看this answer,也许这将有助于
不适合我。 – NehaK
你有没有试过collabsing工具栏应用layout_behavouir? –
BottomTab库的名称是什么?它看起来非常好。 – Thracian
@Thracian这是简单的布局与自己的logick,ty – TazmanOne