このトピックについてここでさまざまな質問を読みましたが、それでも答えが見つかりません。なんらかの理由でこの質問を閉じてください。
Circle
を拡張する単純なクラスがありますView
。
このクラスのコードは次のとおりです。
public class ProgressCircle extends View {
Paint mCirclePaint;
float extRadius;
float viewWidth, viewHeight;
float centerX, centerY;
public ProgressCircle(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
init();
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
float xpad = (float) getPaddingLeft() + getPaddingRight();
float ypad = (float) getPaddingTop() + getPaddingBottom();
float ww = (float)w - xpad; float hh = (float)h - ypad;
extRadius = Math.min(ww, hh) / 2;
viewWidth = this.getWidth();
viewHeight = this.getHeight();
centerX = viewWidth / 2; centerY = viewHeight / 2;
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(centerX, centerY, extRadius, mCirclePaint);
canvas.drawText("ciao", 0, 0, mCirclePaint);
}
private void init() {
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setColor(0x666666);
mCirclePaint.setStyle(Paint.Style.FILL_AND_STROKE);
}
このクラスのすべてのメソッドは、メインアクティビティが作成されるときに呼び出されることを確認しました(いくつかLog.d()
のを使用して)。<com.mypackage.Circle>
メインアクティビティに要素を追加しLinearLayout
、その後、サンプルのテストボタンを追加しました。
私が達成したことは、ボタンが表示されてCircle
いないときに表示されることですが、それでもボタン(のLinearLayout
後にあるCircle
)はレイアウトの最初の要素ではありません。これにより、実際に何かが起こっていると思いますが、何も描画されません。