冲刺1

内容:

  1.确认了用户在MYSQL数据库中的储存结构

  2.将UI原型中的占位符替换成实体

  3.完成了公告栏的制作

 

公告栏功能:

  1.当用户鼠标向左向右滑动时,公告栏的图片也会随着滑向前一张或后一张

  2.每隔五秒将自动跳转到下一张

 

难点:

  如何让程序每个五秒执行一段代码

 

程序实现:

  控制时间

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                if (msg.what == 0) {
                    if(index==num-1){
                        is.setImageResource(gonggao[0]);
                        index=0;
                        Log.d("MainActivity", "1");
                    }else{
                        is.setImageResource(gonggao[index+1]);
                        index++;
                        Log.d("MainActivity", "2");
                    }
                    Log.d("MainActivity", "123456");
                }
            }
        };
 
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                // (1) 使用handler发送消息
                Message message=new Message();
                message.what=0;
                handler.sendMessage(message);
            }
        },0,5000);

  控制手指滑动:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//触摸监听器.
        is.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
 
                //判断是否按下
                if(event.getAction()==MotionEvent.ACTION_DOWN)
                {
                    touchDownX=event.getX();
                    return true;
                }else if(event.getAction()==MotionEvent.ACTION_UP){
                    touchUpX=event.getX();
                    //从左向右滑动
                    if(touchUpX-touchDownX>100){
                        index=index==0?gonggao.length-1:index-1;
                        /*在这里放滑动的动画.  */
                        /**/
                        is.setImageResource(gonggao[index]);
                    }else if(touchDownX-touchUpX>100){
                        index=index==gonggao.length-1?0:index+1;
                        /*在这里放滑动的动画.  */
                        /**/
                        is.setImageResource(gonggao[index]);
 
                    }
                    return true;
                }
 
                return false;
            }
        });

  

 

存在的疑问:

  如何让图片播放平滑滑动的图片?

posted @ 2020-04-18 21:46  瞬沐队  阅读(140)  评论(0编辑  收藏  举报