Search code examples
androidandroid-canvasrect

android:Drawing of rectangle or oval depending on height


I have a list of path objects which are rectangles stored in an arraylist.

This is my code as shown below:

    for (RectF rec : rects) {

        for( int i =0; i< rects.size(); i++){

            System.out.println(rects.get(i).height() + "g");
            while(rects.get(i).height() !=50 ){

                canvas.drawRect(rec, paint);
            }
                canvas.drawOval(rec, paint);

            }

    }

Basically, when the rectangle height is not equal to 50, I would like to draw an oval instead of a rectangle. Upon running the code above, both the oval and rectangle was drawn. What is wrong here? Please help thank you.


Solution

  • for (RectF rec : rects) {
        System.out.println(rec.height() + "g");
    
        if(rec.height() != 50)
        {
            canvas.drawOval(rec, paint);
        }
        else
        {
            canvas.drawRect(rec, paint);
        }
    }