首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >RecyclerView和CoordinatorLayout.Behavior

RecyclerView和CoordinatorLayout.Behavior
EN

Stack Overflow用户
提问于 2017-08-03 06:19:06
回答 1查看 2.9K关注 0票数 0

我想了解协调员的自定义行为如何工作,所以我已经做了一个项目,当一个回收视图滚动,按钮Y规模变化。这是我的xml布局:

代码语言:javascript
复制
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/mp_recycleview1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/cardview_light_background"
        android:paddingBottom="5dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:paddingTop="5dp"
        android:scrollbars="vertical" />

        <Button
            android:id="@+id/button2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cardview_dark_background"
            android:backgroundTint="@color/colorPrimary"
            android:text="Button"
            app:layout_behavior=".MyBehavior"
            android:textColor="@android:color/white"
            />
</android.support.design.widget.CoordinatorLayout>

这是我的行为课

代码语言:javascript
复制
public class MyBehavior extends CoordinatorLayout.Behavior<Button> {
    private final static String TAG = "MyBehavior";

    public MyBehavior(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean layoutDependsOn(CoordinatorLayout parent, Button child, View dependency) {
        return dependency instanceof RecyclerView;

    }

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, Button child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        child.setScaleY(((RecyclerView)target).computeVerticalScrollOffset());


    }
}

但是当我滚动RecyclerView时,什么都不会发生。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-03 06:38:46

头举起来,

为了接收onNestedScroll() onStartNestedScroll 呼叫,需要重写onStartNestedScroll以返回 true**.**。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45476294

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档