ho definito una classe del genere:proprio layout definito, non il metodo OnDraw() sempre chiamato
public class TestMyFrameLayout extends FrameLayout{
Paint mPaint;
public TestMyFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TestMyFrameLayout(Context context) {
super(context);
mPaint = new Paint();
mPaint.setColor(Color.GREEN);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(50f, 50f, 30, mPaint);
}
}
e lo ha chiamato come:
TestMyFrameLayout myFrameLayout = new TestMyFrameLayout(this);
LayoutParams myFrameLayoutParams = new LayoutParams(300,300);
myFrameLayout.setLayoutParams(myFrameLayoutParams);
setContentView(myFrameLayout);
ma in realtà TestMyFrameLayout.onDraw (Tela) funzione non viene chiamata, perché?
Puoi mostrare il codice dove lo usi? Aggiungi anche '@ Override' prima di onDraw: questo controllerà l'errore di battitura in eclissi. –
Grazie, Laurent '. Il mio problema è già risolto. Aggiungi this.setWillNotDraw (false); –