我想画多个圆圈,就像我输入的数字一样。
但我不知道如何创建任意数量的对象。
我只知道以下方法。
Paint circle1 = new Paint();
Paint circle2 = new Paint();
...
如何制作多个画图对象?
发布于 2015-07-19 18:04:35
不需要创建多个Paint对象。只有你需要一个颜色数组为你的圆圈,也需要一个数组他们的位置和半径。
在您的onDraw方法的View中这样做
private Paint mPaint = new Paint();
@Override
protected void onDraw(Canvas canvas) {
for(int i = 0 ; i<n ;i++){
mPaint.setColor(color);
canvas.drawCircle(cx,cy,radius,mPaint);
}
}发布于 2015-07-19 18:07:10
使用for/while循环获取所需的对象数量,并使用ArrayList存储新创建的对象-
List<Paint> paints = new ArrayList<Paint>();
for(int i=0; i<numberYouEntered; i++){
Paint paint = new Paint();
paints.add(paint);
}发布于 2015-07-19 18:11:32
试一试颜料阵列
final int MAX_NUM=10;// Specify whatever number you want
Paint[] circle=new Paint[MAX_NUM];
for(int i=0;i<MAX_NUM;i++){
circle[i]=new Paint();
circle[i].setColor(color);
//specify other attributes
}https://stackoverflow.com/questions/31504222
复制相似问题