我在片段此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不是最丰富的元素。
感谢您的回答。
你有没有试过collabsing工具栏应用layout_behavouir? –
BottomTab库的名称是什么?它看起来非常好。 – Thracian
@Thracian这是简单的布局与自己的logick,ty – TazmanOne