• 冲刺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;
                }
            });

      

    存在的疑问:

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

  • 相关阅读:
    类型-String:二进制安全
    影视-纪录片:《魅力柬埔寨》
    植物:探矿植物
    植物-探矿植物:铜草
    扩展名:cs
    扩展名:snk
    Code-Helper:OracleHelper.cs
    Code-Helper:SqlHelper.cs
    Linux: FTP服务原理及vsfptd的安装、配置
    Linux下/etc/fstab文件详解
  • 原文地址:https://www.cnblogs.com/shunmu/p/12728351.html
Copyright © 2020-2023  润新知