gpt4 book ai didi

android - 如何在 Android 中创建一个球?

转载 作者:太空狗 更新时间:2023-10-29 13:33:42 25 4
gpt4 key购买 nike

我一直在尝试在 Eclipse 中创建一个球。我试图在 this post 中找出要做什么而且我似乎无法弄清楚在我的 Ball 课上放什么。有什么建议吗?

最佳答案

如果您决定改变主意,请试试这个。

public class MainActivity extends Activity {
private int c = Color.YELLOW;
private Canvas g;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
draw();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}


// draws the ball
public void draw ()
{
Display display = getWindowManager().getDefaultDisplay();

int width = display.getHeight();
int height = display.getWidth();

Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);

g = new Canvas(bitmap);
g.drawColor(c);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
g.drawCircle(50, 10, 25, paint); //Put your values

// In order to display this image, we need to create a new ImageView that we can display.
ImageView imageView = new ImageView(this);

// Set this ImageView's bitmap to ours
imageView.setImageBitmap(bitmap);

// Create a simple layout and add imageview to it.
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(imageView, params);
layout.setBackgroundColor(Color.BLACK);

// Show layout in activity.
setContentView(layout);
}
}

关于android - 如何在 Android 中创建一个球?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12943475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com