简体   繁体   English

使用图像按钮和TextView生成自定义时钟

[英]Generating customized clock using Image Button and TextView

I'm new to Android and have been stuck with this issue for sometime now. 我是Android的新手,并且已经有一段时间被这个问题困扰了。 I'm trying to implement a customized clock in my app using imageviews on top and bottom of fields which shows the number-data of the hour or minute. 我正在尝试使用字段顶部和底部的imageviews在我的应用程序中实现自定义时钟,该视图显示小时或分钟的数字数据。 What I have so far accomplished of doing was implementing a touchevent on these imageviews to either increase my time or to decrease my time. 到目前为止,我要做的就是在这些图像视图上实现一个touchevent,以增加我的时间或减少我的时间。

One feature that I am trying to add into this is to have my textviews recognize "fling" motion of the user and go increasing/decreasing based on the direction of the fling. 我要添加到其中的一个功能是让我的文本视图识别用户的“猛扑”动作,并根据猛扑的方向进行增加/减少。

To do this, I have been searching on the web for these "fling" implementations of which I have found to be the following: 为此,我一直在网上搜索以下这些“文件”实现:

minute.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, final MotionEvent event) {
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public boolean onDown(MotionEvent e) {
                    minute.dispatchTouchEvent(e);
                    Log.d("fling", "down");
                    return false;
                }

                @Override
                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
                    minute.dispatchTouchEvent(event);
                    Log.d("fling", "Flinged.");
                    return true;
                }

                @Override
                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
                    return false;
                }
            };
            return false;
        }
    });

which, I have put into the onTouchEvent of my minute textview field. 我已将其放入我的minute textview字段的onTouchEvent中。

With or without the minute.dispatchTouchEvent lines within my onDown and onFling methods, I do not get any logs in my logcat, from which I assume that this gesturemotion is not being dispatched to my minute field. 在我的onDown和onFling方法中,无论是否minute.dispatchTouchEvent行,我在logcat中都不会收到任何日志,我认为从中不会将此手势动作调度到我的分钟字段中。

How do I resolve this issue? 我该如何解决这个问题? Thanks in advance for help :D 在此先感谢您的帮助:D

Issue resolved via using NumberPicker to simulate the a digital clock. 通过使用NumberPicker模拟数字时钟解决了问题。

To my app's requirements, I set the wrap to false and min and max value to be reversed to have the "fling down" action simulate incrementing the desired time. 根据我的应用程序的要求,我将自动换行设置为false,并将最小值和最大值反转,以使“下移”操作模拟所需时间的增加。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM