安卓 大转盘效果

来源:互联网 发布:淘宝客服工作手册 编辑:程序博客网 时间:2024/06/11 23:41

这是一个转盘转动的效果


//线程启动后开始进行刮奖操作

private void startRun() {

        thread = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    set_destdegree(i);
                    Message msg = new Message();
                    msg.what = 1;
                    hand.sendMessage(msg);
                    Thread.sleep(1000);
                    Message msg1 = new Message();
                    msg1.what = 2;
                    hand.sendMessage(msg1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
    }

    private RotateAnimation ani;

int i;//中奖结果

    private Handler hand = new Handler() {

        public void handleMessage(android.os.Message msg) {

//开始动画旋转

//table是转盘,point是指针

            if (msg.what == 1) {
                ani = new RotateAnimation(0f, destdegree,
                        Animation.RELATIVE_TO_SELF, 0.5f,
                        Animation.RELATIVE_TO_SELF, 0.5f);
                ani.setFillAfter(true);
                ani.setDuration(800);
                table.startAnimation(ani);
                point.setClickable(false);

            } else if (msg.what == 2) {

//显示结果

                Toast.makeText(getApplicationContext(), “您的结果是”+i,
                        Toast.LENGTH_LONG).show();
                // 如果允许再转一次,就设置clickable为true
                point.setClickable(true);
            }
        };

    };

//计算旋转角度

    public int set_destdegree(int i,int n) {
       int  destdegree = 360/n * i + 360 * 3;

       return destdegree;
    }


0 0
原创粉丝点击