在滚动中的Andr​​oid视觉指示 [英] visual indication of over scroll in android

查看:164
本文介绍了在滚动中的Andr​​oid视觉指示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一些视觉指示,有在ViewPager所期望的方向一扔没有更多的网页。但是我在努力找到一个地方,在那里把相关的code。

我曾尝试与下面code扩展ViewPager类,但是面包不显示( ev.getOrientation()返回始终为0)。我也尝试过同样的历史点,但 ev.getHistorySize()返回也为0。

我在想什么?

类的例子:

公共类CustomViewPager扩展ViewPager {     公共CustomViewPager(上下文的背景下){         超(上下文);     }     公共CustomViewPager(上下文的背景下,ATTRS的AttributeSet){         超(背景下,ATTRS);     }     / **      * @see android.support.v4.view.ViewPager#的onTouchEvent(android.view.MotionEvent)      * /     @覆盖     公共布尔的onTouchEvent(MotionEvent EV){         布尔结果= super.onTouchEvent(EV);         开关(ev.getAction()及MotionEventCompat.ACTION_MASK){             案例MotionEvent.ACTION_MOVE:                 如果(ev.getOrientation()大于0){                     Toast.makeText(的getContext(),左,0).show();                 }         }         返回结果;     } }

解决方案

如果你看一下V4支持库,你会看到有使用ViewPager名为<一类href="http://developer.android.com/reference/android/support/v4/widget/EdgeEffectCompat.html">EdgeEffectCompat (这提供了光晕效果,当你到达ICS +视图寻呼机的开头或结尾),如果你看一下在COMPAT库的实施,你会看到它有一个if语句,看看内部版本是14+( ICS)或没有。如果是,则它使用正常 EdgeEffect 的这是inroduced在ICS类。否则,它使用BaseEdgeEffectImpl基本上已经没有什么了。

如果你愿意,你可以使用你自己的EdgeEffect自己的自定义ViewPager。你可以看一下Android的源$ C ​​$ C,看看他们是如何实现的EdgeEffect <一href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/EdgeEffect.java">here您可以pretty的多副本(只需确保复制<一href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable-xhdpi/overscroll_edge.png">overscroll_edge和<一href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable-xhdpi/overscroll_glow.png">overscroll_glow在AOSP / RES可绘制/可绘制目录到自己的项目,因为它们是内部的机器人),或继续前进,创造您自己的版本。

祝你好运。

(顺便说一句,这就是他们在创建ICS上的启动菜单中的很酷的边缘倾斜效应......这样你就可以pretty的多少,你想用这句话做创意;)

I am trying to add some visual indication, that there are no more pages in the desired fling direction in the ViewPager. However I am struggling to find a place, where to put relevant code.

I have tried extending ViewPager class with following code, but the Toast is not displaying (ev.getOrientation() returns always 0). I have also tried the same with history points, but ev.getHistorySize() returns also 0.

What am I missing?

Class example:

public class CustomViewPager extends ViewPager {

    public CustomViewPager(Context context) {
        super(context);
    }

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

    /**
     * @see android.support.v4.view.ViewPager#onTouchEvent(android.view.MotionEvent)
     */
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        boolean result = super.onTouchEvent(ev);

        switch (ev.getAction() & MotionEventCompat.ACTION_MASK) {
            case MotionEvent.ACTION_MOVE:
                if (ev.getOrientation() > 0) {
                    Toast.makeText(getContext(), "left", 0).show();
                }
        }

        return result;
    }
}

解决方案

If you look at the v4 support library you will see there's a class used by ViewPager called EdgeEffectCompat (this provides the glow effect when you reach the beginning or end of a view pager in ICS+) If you look at the implementation in the compat library you will see that it has an if-statement to see if the build version is 14+ (ICS) or not. If it is, then it ends up eventually (if you trace long enough) using the normal EdgeEffect class that was inroduced in ICS. Otherwise it uses BaseEdgeEffectImpl which basically has nothing in it.

If you want, you can make your own custom ViewPager that uses EdgeEffect of your own. You can look at the android source code to see how they implemented EdgeEffect here which you can pretty much copy (just make sure to copy the overscroll_edge and overscroll_glow drawables in the AOSP /res/drawable directories to your own project since they are internal to android) or go ahead and create your own version.

Good luck.

(By the way, that's how they create the cool looking edge tilt effect in the launcher menu on ICS... so you can pretty much be as creative as you want with this ;)

这篇关于在滚动中的Andr​​oid视觉指示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆