【发布时间】:2017-05-31 03:13:15
【问题描述】:
我在片段中有这个 xml 代码:
<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>
在项目集 ClickListener 上的 Java 类中:
@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 顶部有一些元素(滚动时它们被隐藏)。
我认为这个问题是设置行为。因为如果我先滚动回收器,AppBar 不会开始扩展,而 Recycler 不是丰富的元素顶部。
感谢您的回答。
【问题讨论】:
-
您是否尝试在协作工具栏上应用 layout_behavouir ??
-
BottomTab 库的名称是什么?看起来很不错。
-
@Thracian 这是一个简单的布局,有自己的逻辑,ty
-
您好,您找到解决方案了吗?
-
@NehaK 找到这个答案帮助我。解决方法:将根元素更改为 NestedScrollView,向其中添加回收器,然后将 nestedscrollingEnabled = true 添加到 NestedScrollView (>21ApI) 或使用 NestedScrollChildHelper 支持 libr
标签: android android-recyclerview android-coordinatorlayout smooth-scrolling