Android 虚拟摇杆,多种模式回调,返回距离级别,方向,角度。

K-RockerView

项目地址: jinkai1994/JK-RockerView
简介:Android 虚拟摇杆,多种模式回调,返回距离级别,方向,角度。

使用方法

①attr 中定义自定义参数

  

    
    
    
    
    
        
        
    

②复制 RockerView 到项目中

③使用摇杆控件


③事件回调

 mRockerView.setOnShakeListener(DIRECTION_8, new RockerView.OnShakeListener() {
        @Override
        public void onStart() {

        }

        @Override
        public void direction(RockerView.Direction direction) {
            if (direction == RockerView.Direction.DIRECTION_CENTER){
                mTvShake.setText("当前方向:中心");
            }else if (direction == RockerView.Direction.DIRECTION_DOWN){
                mTvShake.setText("当前方向:下");
            }else if (direction == RockerView.Direction.DIRECTION_LEFT){
                mTvShake.setText("当前方向:左");
            }else if (direction == RockerView.Direction.DIRECTION_UP){
                mTvShake.setText("当前方向:上");
            }else if (direction == RockerView.Direction.DIRECTION_RIGHT){
                mTvShake.setText("当前方向:右");
            }else if (direction == RockerView.Direction.DIRECTION_DOWN_LEFT){
                mTvShake.setText("当前方向:左下");
            }else if (direction == RockerView.Direction.DIRECTION_DOWN_RIGHT){
                mTvShake.setText("当前方向:右下");
            }else if (direction == RockerView.Direction.DIRECTION_UP_LEFT){
                mTvShake.setText("当前方向:左上");
            }else if (direction == RockerView.Direction.DIRECTION_UP_RIGHT){
                mTvShake.setText("当前方向:右上");
            }
        }

        @Override
        public void onFinish() {

        }
    });
    mRockerView.setOnAngleChangeListener(new RockerView.OnAngleChangeListener() {
        @Override
        public void onStart() {

        }

        @Override
        public void angle(double angle) {
            mTvAngle.setText("当前角度:"+angle);
        }

        @Override
        public void onFinish() {

        }
    });

    mRockerView.setOnDistanceLevelListener(new RockerView.OnDistanceLevelListener() {
        @Override
        public void onDistanceLevel(int level) {
            mTvLevel.setText("当前距离级别:"+level);
        }
    });

你可能感兴趣的:(Android,自定义控件进阶,android)