我有下一个问题:
我有一个活动,我想尝试添加按钮,这是我的 onCreate 方法
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
DrawView drawView = new DrawView(this);
setContentView(drawView);
context = this;
drawView.requestFocus();
}
这是 DrawView 类
公共类 DrawView 扩展视图实现 OnTouchListener {
public static final String TAG = "DrawView";
private List<List<Point>> listaPuntos = null;
private List<Paint> listaPaints = null;
private int paintActual = 0;
public DrawView(Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
listaPaints = new ArrayList<Paint>();
listaPuntos = new ArrayList<List<Point>>();
this.setOnTouchListener(this);
this.setBackgroundColor(Color.WHITE);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(Color.BLACK);
listaPaints.add(paint);
}
@Override
public void onDraw(Canvas canvas) {
for(int i=0; i<listaPaints.size(); i++){
Paint paint = listaPaints.get(i);
Point punto = null;
if(listaPuntos.size()!=0 && listaPuntos.size()>i){
List<Point> puntos = listaPuntos.get(i);
for (Point point : puntos) {
if(punto == null){
punto = point;
}
canvas.drawLine(point.x, point.y, punto.x, punto.y, paint);
punto = point;
}
}
}
}
@Override
public boolean onTouch(View view, MotionEvent event) {
if(event.getAction() != MotionEvent.ACTION_UP){
Point point = new Point();
point.x = event.getX();
point.y = event.getY();
point.paintPunto = paintActual;
if(listaPuntos.size()<=paintActual){
listaPuntos.add(new ArrayList<Point>());
}
listaPuntos.get(paintActual).add(point);
invalidate();
return true;
}else{
paintActual++;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(2);
paint.setColor(Color.BLACK);
listaPaints.add(paint);
}
return super.onTouchEvent(event);
}
任何人都知道如何将按钮添加到此活动?我想添加一个按钮来执行操作,但我完全不能!
非常感谢你的帮助。