使用setValue方法时,Android的NumberPicker动画轮 [英] Android NumberPicker animate wheel when using setValue method

查看:594
本文介绍了使用setValue方法时,Android的NumberPicker动画轮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让动画的numberPicker的车轮。我找到了相应的问题在这里:

i m trying to get the wheel of the numberPicker animated. I found the corresponding question here:

<一个href=\"http://stackoverflow.com/questions/13500852/how-to-change-numberpickers-value-with-animation\">How与动画改变NumberPicker的价值?

但我不能与suppposed答案解决它。有人能帮帮我吗?

But i cannot solve it with the suppposed answers. Can somebody please help me?

在改变numberPicker的值从可以说100到200,我想车轮与旧值到新的增量。车轮应滑动到新的价值。在链接passsy与反思解决它,但我不知道如何在实践中使用它。

When changing the value of the numberPicker from lets say 100 to 200, i want the wheel to increment from the old value to the new one. The wheel should slide to the new value. In the link passsy solved it with reflection but i don t know how to use it in practice..

感谢。

推荐答案

,如果你想通过有一个以增加数值真的很简单。

It's really simple if you want to increment the value by one.

只是叫 changeValueByOne(myNumberPicker,真实); 一个动画递增numberpicker。 (假递减)

just call changeValueByOne(myNumberPicker, true); to increment the numberpicker by one with animation. (false to decrement)

100-200增量是不可能用这种方法

increment from 100-200 is not possible with this method

            /**
             * using reflection to change the value because
             * changeValueByOne is a private function and setValue
             * doesn't call the onValueChange listener.
             * 
             * @param higherPicker
             *            the higher picker
             * @param increment
             *            the increment
             */
            private void changeValueByOne(final NumberPicker higherPicker, final boolean increment) {

            Method method;
            try {
                // refelction call for
                // higherPicker.changeValueByOne(true);
                method = higherPicker.getClass().getDeclaredMethod("changeValueByOne", boolean.class);
                method.setAccessible(true);
                method.invoke(higherPicker, increment);

            } catch (final NoSuchMethodException e) {
                e.printStackTrace();
            } catch (final IllegalArgumentException e) {
                e.printStackTrace();
            } catch (final IllegalAccessException e) {
                e.printStackTrace();
            } catch (final InvocationTargetException e) {
                e.printStackTrace();
            }
        }

这篇关于使用setValue方法时,Android的NumberPicker动画轮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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