Android 画布上的按钮

Android 画布上的按钮,android,canvas,draw,Android,Canvas,Draw,我正在尝试制作一个使用画布的简单游戏,我想在右上角放一个按钮,让你暂停游戏。 最好的方法是什么 我想画两条线,象征着暂停在画布上,在玩家点击位置后暂停游戏,但是没有更好的方法吗 我在这里还放了一张图片,向您展示我希望它的样子: 我使用相对布局来管理所有内容 1) 找到相对的布局 2) 在你的相对论中添加一些东西 3) 将画布添加到您的RelativeLayout 下面的示例通过simple for loop绘制了四个按钮,并添加画布 例如: RelativeLayout layout = (Re

我正在尝试制作一个使用画布的简单游戏,我想在右上角放一个按钮,让你暂停游戏。 最好的方法是什么

我想画两条线,象征着暂停在画布上,在玩家点击位置后暂停游戏,但是没有更好的方法吗

我在这里还放了一张图片,向您展示我希望它的样子:


我使用相对布局来管理所有内容

1) 找到相对的布局

2) 在你的相对论中添加一些东西

3) 将画布添加到您的RelativeLayout

下面的示例通过simple for loop绘制了四个按钮,并添加画布

例如:

RelativeLayout layout = (RelativeLayout)findViewById(R.id.bb);
for (int i=0; i<4; i++) {
    Button btn = new Button(this);
    btn.setId(i);
    btn.setText("some_text");
    btn.setHeight(i*100);
    btn.setX(100*i);
    btn.setY(100*i);
    layout.addView(btn);
}
YourDesign abc=new YourDesign(this);
layout.addView(abc);
public class YourDesign extends View{

Bitmap picture;
int x=0;

public YourDesign(Context context) {
    super(context);
    picture=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
}

@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    canvas.drawBitmap(picture, x, 100, new Paint());
    x++;
    if(x>canvas.getWidth())
        x=0;
    invalidate();
}