안드로이드 캔버스 사용법에 대한 자습서가 거의 없습니다. 그러나 공식 문서를보고 나서이 코드를 생성 할 수있었습니다. 나는 단순히 녹색 직사각형을 그리기를 원한다.안드로이드 캔버스 그림이 아닙니다
public class LevelActivity extends AppCompatActivity {
Object shape;
Target target;
Rect r;
Paint paint;
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.FILL);
r = new Rect();
r.set(0,0,c.getWidth(),c.getHeight()/2);
c.drawRect(r,paint);
shape = new Shape(30,10); //Object setup
//shape.pick(); //Pick random point for target
}
}
나는 그리기 위해 customView를 사용하고 싶지 않다. 순수한 안드로이드 캔버스를 사용하고 싶다. 코드를 실행할 때 오류 또는 경고가 표시되지 않습니다.
도움을 주시면 대단히 감사하겠습니다.
-Kelton
당신은보기에 캔버스를 그릴 필요가있다. –
@MatthewHooker 이것이 뷰를 구현하는 새로운 클래스를 만들어야한다는 것을 의미합니까? 아니면 내가 어떻게 할 것인가? –
findViewById가보기를 가져옵니다. https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html –