I'm having trouble drawing a circle to the screen. I do not know if I'm approaching this correctly, or if I have to use a bitmap. Below is a Circle class I created for specifically creating a circle to my specifications.
package com.example.alex.parkinsonsdiseaseapp;
import android.view.View;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
public class Circle extends View {
private final float x;
private final float y;
private final int r;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
public Circle(Context context, float x, float y, int r) {
super(context);
mPaint.setColor(0x000000);
this.x = x;
this.y = y;
this.r = r;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(x, y, r, mPaint);
}
}
Below is the Activity in which the above class gets used.
package com.example.alex.parkinsonsdiseaseapp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
public class FingerTappingActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_finger_tapping);
LinearLayout circle = (LinearLayout) findViewById(R.id.lt);
View circleView = new Circle(this, 100, 100, 100);
circleView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
circle.addView(circleView);
Toast.makeText(FingerTappingActivity.this, "Test", Toast.LENGTH_SHORT).show();
}
}