Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 帆布不';在安卓系统中似乎没有旋转_Java_Android_Android Canvas_Custom View - Fatal编程技术网

Java 帆布不';在安卓系统中似乎没有旋转

Java 帆布不';在安卓系统中似乎没有旋转,java,android,android-canvas,custom-view,Java,Android,Android Canvas,Custom View,我旋转画布有困难。我画了一个圆和一个弧 我试着向手机摄像头旋转的方向旋转。 代码如下 ViewSearch.java public void onSensorChanged(SensorEvent event) { // RelativeLayout rl = (RelativeLayout) // findViewById(R.layout.visualsearch); aziumth_angle = event.values[0]; // degrees of r

我旋转画布有困难。我画了一个圆和一个弧

我试着向手机摄像头旋转的方向旋转。 代码如下

ViewSearch.java

 public void onSensorChanged(SensorEvent event) {
    // RelativeLayout rl = (RelativeLayout)
    // findViewById(R.layout.visualsearch);
    aziumth_angle = event.values[0]; // degrees of rotation around the
                                        // z axis
    pitch_angle = event.values[1]; // degrees of rotation around the x
                                    // axis
    float roll_angle = event.values[2]; // degrees of rotation around the y
                                        // axis
    TextView txtangle = (TextView) findViewById(R.id.txtangle);
    txtangle.setText("Z : " + aziumth_angle + ", X : " + pitch_angle
            + ", Y : " + roll_angle);

    CustomView cv = new CustomView(this);
    cv.updateData(aziumth_angle);

}
public class CustomView extends View {
Paint paint;
Paint paintarc;
public float position;
private int rotationAngle = 0;
private int arcSweepAngle = 45;
public float azimuth;
public float startAngle;

public CustomView(Context context) {
    super(context);
    setWillNotDraw(false);
    startdraw();

}

public CustomView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);
    startdraw();
}

public CustomView(Context context, AttributeSet attrs, int defstyle) {
    super(context, attrs, defstyle);
    setWillNotDraw(false);
    startdraw();
}

public void startdraw() {
    paint = new Paint();
    paintarc = new Paint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(2);
    paint.setTextSize(25);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.WHITE);
    Shader gradient = new SweepGradient(0, getMeasuredHeight() / 2,
            Color.RED, Color.WHITE);
    paintarc.setShader(gradient);
    paintarc.setStrokeWidth(43);
}

@SuppressLint("NewApi")
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int xPoint = getMeasuredWidth() / 2;
    int yPoint = getMeasuredHeight() / 2;

    float radius = (float) (Math.max(xPoint, yPoint) * 0.6); // why is this?
    canvas.drawCircle(xPoint, yPoint, radius, paint);

    // 3.143 is a good approximation for the circle

    float width = (float) getWidth();
    float height = (float) getHeight();

    // determine center point to the circle.
    float center_x;
    float center_y;
    center_x = width / 2;
    center_y = height / 2;
    VisualView vv = null;
    azimuth = vv.aziumth_angle;
    startAngle = vv.pitch_angle;        
    final RectF oval = new RectF();
    oval.set(center_x - radius,center_y - radius,center_x + radius,center_y + radius);
    canvas.drawArc(oval, 0, 60, true, paintarc);
    canvas.translate(0, startAngle);
    canvas.rotate(-position * 360 / (2 * 3.14159f), center_x, center_y);
    }

public void updateData(float position) {
    this.position = position;
    invalidate();
}
}
CustomView.java

 public void onSensorChanged(SensorEvent event) {
    // RelativeLayout rl = (RelativeLayout)
    // findViewById(R.layout.visualsearch);
    aziumth_angle = event.values[0]; // degrees of rotation around the
                                        // z axis
    pitch_angle = event.values[1]; // degrees of rotation around the x
                                    // axis
    float roll_angle = event.values[2]; // degrees of rotation around the y
                                        // axis
    TextView txtangle = (TextView) findViewById(R.id.txtangle);
    txtangle.setText("Z : " + aziumth_angle + ", X : " + pitch_angle
            + ", Y : " + roll_angle);

    CustomView cv = new CustomView(this);
    cv.updateData(aziumth_angle);

}
public class CustomView extends View {
Paint paint;
Paint paintarc;
public float position;
private int rotationAngle = 0;
private int arcSweepAngle = 45;
public float azimuth;
public float startAngle;

public CustomView(Context context) {
    super(context);
    setWillNotDraw(false);
    startdraw();

}

public CustomView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setWillNotDraw(false);
    startdraw();
}

public CustomView(Context context, AttributeSet attrs, int defstyle) {
    super(context, attrs, defstyle);
    setWillNotDraw(false);
    startdraw();
}

public void startdraw() {
    paint = new Paint();
    paintarc = new Paint();
    paint.setAntiAlias(true);
    paint.setStrokeWidth(2);
    paint.setTextSize(25);
    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(Color.WHITE);
    Shader gradient = new SweepGradient(0, getMeasuredHeight() / 2,
            Color.RED, Color.WHITE);
    paintarc.setShader(gradient);
    paintarc.setStrokeWidth(43);
}

@SuppressLint("NewApi")
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int xPoint = getMeasuredWidth() / 2;
    int yPoint = getMeasuredHeight() / 2;

    float radius = (float) (Math.max(xPoint, yPoint) * 0.6); // why is this?
    canvas.drawCircle(xPoint, yPoint, radius, paint);

    // 3.143 is a good approximation for the circle

    float width = (float) getWidth();
    float height = (float) getHeight();

    // determine center point to the circle.
    float center_x;
    float center_y;
    center_x = width / 2;
    center_y = height / 2;
    VisualView vv = null;
    azimuth = vv.aziumth_angle;
    startAngle = vv.pitch_angle;        
    final RectF oval = new RectF();
    oval.set(center_x - radius,center_y - radius,center_x + radius,center_y + radius);
    canvas.drawArc(oval, 0, 60, true, paintarc);
    canvas.translate(0, startAngle);
    canvas.rotate(-position * 360 / (2 * 3.14159f), center_x, center_y);
    }

public void updateData(float position) {
    this.position = position;
    invalidate();
}
}
当传感器方向改变时,我正在检索
方位
值,并试图通过传递
方位
值来旋转画布。但是画布没有旋转或更新

我错过了什么