Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FrameLayout frame = (FrameLayout) findViewById(R.id.frame);
- for(int i=0;i<=9;i++){
- DrawCircles c = new DrawCircles(getApplicationContext());
- frame.addView(c);
- }
- public class DrawCircles extends View {
- int red = (int) (Math.random() * 255);
- int green = (int) (Math.random() * 255);
- int blue = (int) (Math.random() * 255);
- public DrawCircles(Context con)
- {
- super(con);
- }
- @SuppressLint("DrawAllocation")
- @Override
- public void onDraw(Canvas c)
- {
- super.onDraw(c);
- int minRadius = 100;
- Random random = new Random();//define this outside you onDraw fucntion
- int w = getWidth();
- int h = getHeight();
- int randX = random.nextInt(w);
- int randY = random.nextInt(h);
- int randR = minRadius + random.nextInt(100);
- Log.e("randX",">>"+randX+","+randR);
- int color = Color.rgb(red, green, blue);
- int rand = (int)(Math.random() * 200);
- Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
- p.setAntiAlias(true);
- p.setStyle(Paint.Style.STROKE);
- p.setStrokeWidth(100);
- p.setColor(color);
- p.setStyle(Paint.Style.FILL);
- // c.drawCircle(rand, rand, rand, p);
- c.drawCircle(randX, randY, randR, p);
- clear(c);
- }
- public void clear(Canvas c)
- {
- c.drawColor(Color.TRANSPARENT);
- }
- public void drawColor(int transparent) {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement