2014年12月8日 星期一

draw a smaller ShapeDrawable inside another shapeDrawable programmatically

  出處:http://stackoverflow.com/questions/13992094/how-to-draw-a-smaller-shapedrawable-inside-another-shapedrawable-programmaticall
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

沒有留言:

張貼留言