【发布时间】:2015-08-12 04:38:19
【问题描述】:
我有一个 LinearLayout,当我在 RecyclerView 上向上滚动时我想隐藏它,并在我向下滚动时重新出现;行为应该就像工具栏隐藏和重新出现的方式一样。
这是我目前所拥有的:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/viewToHideOnScroll
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- other stuff inside the LinearLayout -->
</LinearLayout>
<RecyclerView
android:id="@+id/recyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
据我目前所知,我可以在viewToHideOnScroll 上指定一个app:layout_behavior 值,以便它根据recyclerView 上的滚动事件平滑滚动进出视图。为此,我必须编写一个自定义类ViewToHideOnScrollBehavior 并覆盖layoutDependsOn 和其他一些方法(onNestedScroll?)。
如果那是正确的,这就是我所拥有的:
public class ViewToHideOnScrollBehavior extends CoordinatorLayout.Behavior<LinearLayout> {
public ViewToHideOnScrollBehavior(Context context, AttributeSet attrs) {}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, LinearLayout child, View dependency) {
return dependency instanceof RecyclerView;
}
// some other method to override, I don't know
}
谁能给我一个提示,还是我做错了?
我一直在关注https://lab.getbase.com/introduction-to-coordinator-layout-on-android/
【问题讨论】:
标签: android android-recyclerview android-coordinatorlayout