深度解析android.support.v4.view.NestedScrollingParentHelper类的源码
来源:互联网 发布:网络大学考试平台答案 编辑:程序博客网 时间:2024/06/05 05:12
- 这是一次严肃的源码分析…………….
- 首先请看源码
/* * Copyright (C) 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package android.support.v4.view;import android.view.View;import android.view.ViewGroup;/** * Helper class for implementing nested scrolling parent views compatible with Android platform * versions earlier than Android 5.0 Lollipop (API 21). * * <p>{@link android.view.ViewGroup ViewGroup} subclasses should instantiate a final instance * of this class as a field at construction. For each <code>ViewGroup</code> method that has * a matching method signature in this class, delegate the operation to the helper instance * in an overridden method implementation. This implements the standard framework policy * for nested scrolling.</p> * * <p>Views invoking nested scrolling functionality should always do so from the relevant * {@link android.support.v4.view.ViewCompat}, {@link android.support.v4.view.ViewGroupCompat} or * {@link android.support.v4.view.ViewParentCompat} compatibility * shim static methods. This ensures interoperability with nested scrolling views on Android * 5.0 Lollipop and newer.</p> */public class NestedScrollingParentHelper { private final ViewGroup mViewGroup; private int mNestedScrollAxes; /** * Construct a new helper for a given ViewGroup */ public NestedScrollingParentHelper(ViewGroup viewGroup) { mViewGroup = viewGroup; } /** * Called when a nested scrolling operation initiated by a descendant view is accepted * by this ViewGroup. * * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with * the same signature to implement the standard policy.</p> */ public void onNestedScrollAccepted(View child, View target, int axes) { mNestedScrollAxes = axes; } /** * Return the current axes of nested scrolling for this ViewGroup. * * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with * the same signature to implement the standard policy.</p> */ public int getNestedScrollAxes() { return mNestedScrollAxes; } /** * React to a nested scroll operation ending. * * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with * the same signature to implement the standard policy.</p> * * @param target View that initiated the nested scroll */ public void onStopNestedScroll(View target) { mNestedScrollAxes = 0; }}
- 带上注释,一共86行。
- 看这个类的名字,感觉很高大上的样子,构造函数还要传递一个
View
给它,感觉是要搞出一个大新闻的样子……… - 但是,实际上传递进来的这个
ViewGroup
完全没有任何的意义,可以直接给它一个null
。因为根本没有去调用。 - 再看它的成员方法,一共三个:
public void onNestedScrollAccepted(View child, View target, int axes) { mNestedScrollAxes = axes; }public int getNestedScrollAxes() { return mNestedScrollAxes; }public void onStopNestedScroll(View target) { mNestedScrollAxes = 0; }
- 看到没有,第一个方法,传递过来3个参数,前两个完全没有任何的意义。而这个方法的作用仅仅是将传进来的一个
int
赋值给一个成员变量。 - 然后看第二个方法,实际上就是一个
int getXXX();
的方法。 - 最后一个方法更加没有意义,传递进来一个
view
也是完全没有任何意义的。然后将成员变量设置为0
。
ok,这个类就这样子分析完了。
这个类,好吧,不吐槽了。
0 0
- 深度解析android.support.v4.view.NestedScrollingParentHelper类的源码
- android.support.v4.util.Pools源码解析
- android.support.v4.app.Fragment源码解析
- Android关联源码support-v4的问题解决
- Android关联源码support-v4的问题解决
- Android关联源码support-v4的问题解决
- Android关联源码support-v4的问题解决
- Android关联源码support-v4的问题解决
- android.support.v4.util.Pool 类解析
- android.support.v4.view.PagerAdapter
- Android NestedScrolling,NestedScrollingParent,NestedScrollingParentHelper解析
- Android关联源码support-v4
- 关联android-support-v4源码
- 找不到android.support.v4.view.ViewPager里面的包
- java.lang.NoClassDefFoundError: android.support.v4.view.ViewConfigurationCompat的解决办法
- android.support.v4.view.ViewPager控件的位置
- Android查看android-support-v4.jar源码的方法
- 解决eclipse无法打开android-support-v4的源码
- 总结memcache的原理和使用
- asp.net把网站发布到本机IIS上
- Css设置img属性让图片水平居中/居左/居右的写法
- 各种android应用模仿源码
- USB中断处理
- 深度解析android.support.v4.view.NestedScrollingParentHelper类的源码
- hadoop yarn的运行机制
- 在CentOS7中安装nginx1.9 + nginx-gridfs
- Unity3D NGUI分离RGBA通道
- android中的ellipsize
- Python中的断言
- eclipse下java.lang.OutOfMemoryError: PermGen space解决方法
- Ajax的jsonp跨域请求样例
- WebHdfs API使用和开放WebHdfs使用后权限控制