Hello,
I must draw Button ( or any component View ) on canvas.
Anyone know, it is posible and what i must do??
I trying solution:
mybutton.draw(canvas) in override method onDraw but my button isn't drawn


public class Game extends View {
Button _button;
public Game(Context context) {
super(context);
_button = new Button(context);
_button.measure(50, 50);
_button.layout(20,20,20,20);
}
@Override
protected void onDraw(Canvas canvas) {;
_button.draw(canvas);
postInvalidate();
}
}


int width = _button.getMeasuredWidth();
int height = _button.getMeasuredHeight();
int left = 60;
int top = 60;
_button.layout(left, top, left + width, top + height);






//We use a layout to contain the button (or any view you want to draw)
LinearLayout ll = new LinearLayout(getApplicationContext());
ll.setOrientation(LinearLayout.VERTICAL);
//We set the layout parameters
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
//SET THE MARGIN HERE
layoutParams.setMargins(150, 150, 0, 0);
//Declare a new view (here a button)
Button button=new Button(getApplicationContext());
button.setText("some text");
//Add it to our linear layout
ll.addView(button, layoutParams);
//Measure and layout the linear layout before drawing it
ll.measure(MeasureSpec.getSize(ll.getMeasuredWidth()), MeasureSpec.getSize(ll.getMeasuredHeight()));
ll.layout(0, 0, MeasureSpec.getSize(button.getMeasuredWidth()), MeasureSpec.getSize(button.getMeasuredHeight()));
//Finally draw the linear layout on the canvas
ll.draw(canvas);

Return to Android 2D/3D Graphics - OpenGL Problems
Users browsing this forum: Google Feedfetcher and 5 guests