How to draw a smaller ShapeDrawable inside another shapeDrawable programmatically

后端 未结 1 441
感动是毒
感动是毒 2021-01-01 01:24

Im trying to draw a smaller circle within another circle. It seems pretty simple but Im having trouble with this and couldnt find an answer. The code im using is:



        
相关标签:
1条回答
  • 2021-01-01 01:51

    Change the order,

    Drawable[] d = {smallerCircle,biggerCircle};
    
    LayerDrawable composite1 = new LayerDrawable(d);
    

    try like this

            ShapeDrawable biggerCircle= new ShapeDrawable( new OvalShape());
            biggerCircle.setIntrinsicHeight( 60 );
            biggerCircle.setIntrinsicWidth( 60);
            biggerCircle.setBounds(new Rect(0, 0, 60, 60));
            biggerCircle.getPaint().setColor(Color.BLUE);
    
            ShapeDrawable smallerCircle= new ShapeDrawable( new OvalShape());
            smallerCircle.setIntrinsicHeight( 10 );
            smallerCircle.setIntrinsicWidth( 10);
            smallerCircle.setBounds(new Rect(0, 0, 10, 10));
            smallerCircle.getPaint().setColor(Color.BLACK);
            smallerCircle.setPadding(50,50,50,50);
            Drawable[] d = {smallerCircle,biggerCircle};
    
            LayerDrawable composite1 = new LayerDrawable(d);
    
            btn.setBackgroundDrawable(composite1);  
    

    enter image description here

    0 讨论(0)
提交回复
热议问题