如何画一个小ShapeDrawable另一shapeDrawable内编程(How to draw

2019-07-17 12:21发布

我试着去画另一个圈子内的小圆圈。 这似乎很简单,但有这个麻烦Im和无法找到答案。 使用代码IM是:

    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);

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

但没有工作,什么情况是,小圈获得大如越大圆。 所以,唯一的表现是与biggerCircle大小的黑色圆圈。 我会apriciate如果有人可以帮助。 提前致谢。

Answer 1:

更改顺序,

Drawable[] d = {smallerCircle,biggerCircle};

LayerDrawable composite1 = new LayerDrawable(d);

尝试这样

        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);  



文章来源: How to draw a smaller ShapeDrawable inside another shapeDrawable programmatically