项目作者: Mixiaoxiao

项目描述 :
Add the over-scroll feature to any scrollable view: RecyclerView, ScrollView, WebView, ListView, GridView, etc. Support both fling and drag over-scroll,and easy to customize the over-scroll style. 为任意可滑动的View定制越界效果(over-scroll),同时支持滑动惯性越界与拖动越界,方便地定制与扩展不同的越界风格。实现iOS弹性越界效果、微信“网页由xxx.com提供”的WebView效果、MIUI8的越界拉伸放大效果。
高级语言: Java
项目地址: git://github.com/Mixiaoxiao/OverScroll-Everywhere.git
创建时间: 2016-08-31T15:53:25Z
项目社区:https://github.com/Mixiaoxiao/OverScroll-Everywhere

开源协议:

下载


OverScroll-Everywhere

Add the over-scroll feature to any scrollable view: RecyclerView, ScrollView, WebView, ListView, GridView, etc. Support both fling and drag over-scroll,and easy to customize the over-scroll style.

为任意可滑动的View定制越界效果(over-scroll),同时支持滑动惯性越界与拖动越界,方便地定制与扩展不同的越界风格。实现iOS弹性越界效果、微信“网页由xxx.com提供”的WebView效果、MIUI8的越界拉伸放大效果。
注:安卓本身使用EdgeEffect绘制越界效果(边缘发亮),安卓4.x为固定的holo_blue色,5.0+为半透明colorPrimary色。

OverScroll-Everywhere

Sample

OverScroll-EverywhereSample.apk

GIF

Usage

  • Use OverScrollRecyclerView OverScrollScrollView OverScrollWebView OverScrollListView OverScrollGridView to replace the original one.

  • Enable or disable fling/drag over-scroll

    1. OverScrollRecyclerView yourOverScrollRecyclerView = ...;
    2. boolean dragOverScroll = true | false;
    3. boolean flingOverScroll = true | false;
    4. yourOverScrollRecyclerView.getOverScrollDelegate().setOverScrollType(dragOverScroll, flingOverScroll);

Style

  • Perset style

    1. //Show your logo at top
    2. Drawable yourLogo = ...;
    3. yourOverScrollRecyclerView.getOverScrollDelegate().setOverScrollStyle(new LogoOverScrollStyle(yourLogo));
    4. //Like MIUI8
    5. yourOverScrollRecyclerView.getOverScrollDelegate().setOverScrollStyle(new Miui8OverScrollStyle());
    6. //Show the host of webpage at top
    7. yourOverScrollWebView.getOverScrollDelegate().setOverScrollStyle(new WebHostOverScrollStyle() {
    8. @Override
    9. public String formatUrlHost(String url) {
    10. try {
    11. return "Provided by " + new URL(url).getHost();
    12. } catch (Exception e) {
    13. }
    14. return "";
    15. }
    16. });
  • Customize your style

    1. OverScrollStyle yourOverScrollStyle = new OverScrollStyle() {
    2. /**
    3. * Transform canvas before draw content,
    4. * for example, do canvas.translate
    5. */
    6. public void transformOverScrollCanvas(float offsetY, Canvas canvas, View view) {
    7. final int translateY = Math.round(offsetY * DEFAULT_DRAW_TRANSLATE_RATE);
    8. canvas.translate(0, translateY);
    9. }
    10. /**
    11. * Draw overscroll effect(e.g. logo) at top, the direction of offsetY is
    12. * same as TouchEvent
    13. */
    14. public void drawOverScrollTop(float offsetY, Canvas canvas, View view) {
    15. //draw someting
    16. };
    17. /**
    18. * Draw overscroll effect(e.g. logo) at bottom, the direction of offsetY
    19. * is same as TouchEvent
    20. */
    21. public void drawOverScrollBottom(float offsetY, Canvas canvas, View view) {
    22. //draw someting
    23. };
    24. };
    25. yourOverScrollRecyclerView.getOverScrollDelegate().setOverScrollStyle(yourOverScrollStyle);

    Use with FastScroll-Everywhere


  • Like this

    1. public class FastAndOverScrollScrollView extends ScrollView implements FastScrollable, OverScrollable {
    2. private FastScrollDelegate mFastScrollDelegate;
    3. private OverScrollDelegate mOverScrollDelegate;
    4. public FastAndOverScrollScrollView(Context context, AttributeSet attrs) {
    5. super(context, attrs);
    6. createDelegates(context);
    7. }
    8. // ===========================================================
    9. // createDelegates
    10. // ===========================================================
    11. private void createDelegates(Context context) {
    12. mFastScrollDelegate = new FastScrollDelegate.Builder(this).build();
    13. mOverScrollDelegate = new OverScrollDelegate(this);
    14. }
    15. // ===========================================================
    16. // Modify these 3 methods, others are same as source code.
    17. // ===========================================================
    18. @Override
    19. public boolean onInterceptTouchEvent(MotionEvent ev) {
    20. if (mFastScrollDelegate.onInterceptTouchEvent(ev)) {
    21. return true;
    22. }
    23. if (mOverScrollDelegate.onInterceptTouchEvent(ev)) {
    24. return true;
    25. }
    26. return super.onInterceptTouchEvent(ev);
    27. }
    28. @Override
    29. public boolean onTouchEvent(MotionEvent event) {
    30. if (mFastScrollDelegate.onTouchEvent(event)) {
    31. return true;
    32. }
    33. if (mOverScrollDelegate.onTouchEvent(event)) {
    34. return true;
    35. }
    36. return super.onTouchEvent(event);
    37. }
    38. @Override
    39. public boolean superAwakenScrollBars() {
    40. // Just call mFastScrollDelegate.awakenScrollBars()
    41. // Do not call super
    42. return awakenScrollBars();
    43. }
    44. // ===========================================================
    45. // Copy other methods from source code.
    46. // ===========================================================
    47. }

Extension (OverScroll-Everywhere!)

  • If you want to add the over-scroll feature to your CustomScrollableView, just copy the source code of OverScrollScrollView(or any OverScrollXxxxView) and change the super-class to your CustomScrollableView.
  • Then, all done. All things are handled by OverScrollDelegate

Attention

  • In RecyclerView, we override the package-method absorbGlows to get the velocity of fling overscroll.
  • In other views, we override the protected-method overScrollBy to compute the velocity of fling overscroll.

Developed By

Mixiaoxiao(谜小小) - xiaochyechye@gmail.com or mixiaoxiaogogo@163.com

License

  1. Copyright 2016 Mixiaoxiao
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.