我尝试为 google 制作视差滚动效果MapView并RecycleView使用CoordinatorLayour.
所以基于在网上找到的一些教程,我做了下面的代码。
布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.gms.maps.MapView android:id="@+id/map_view"
android:layout_width="match_parent"
android:layout_height="200dp"
app:layout_behavior="net.lunavulpo.coordinatorlayouttest.MapViewBehavior"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_marginTop="200dp"
android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
我实现了CoordinatorLayout.Behavior:
public class MapViewBehavior extends CoordinatorLayout.Behavior<MapView> {
public MapViewBehavior(Context context, AttributeSet attrs) {
}
@Override
public boolean layoutDependsOn(CoordinatorLayout parent, MapView child, View dependency) {
return true;
}
@Override
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, MapView child, View directTargetChild, View target, int nestedScrollAxes) {
return true;
}
@Override …Run Code Online (Sandbox Code Playgroud) android google-maps-android-api-2 android-design-library androiddesignsupport android-coordinatorlayout
我有一个View和一个RecyclerView,它位于LinearLayout中.我想要实现的是这样的:
https://material.google.com/patterns/scrolling-techniques.html#scrolling-techniques-behavior
基本上当我向上滚动RecyclerView时,View会折叠.如果我向下滚动RecyclerView,它会扩展.
我尝试了各种方法,但如果手指在滚动位置周围抖动,动画会断断续续.如果手指在一个方向上进行有意的滚动运动,它只会动画很好.我该怎么做呢?