6

我试图在另一个圆圈内画一个较小的圆圈。这看起来很简单,但我遇到了麻烦,找不到答案。我使用的代码是:

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

但这没有用,发生的事情是较小的圆圈与较大的圆圈一样大。所以唯一显示的是更大圆圈大小的黑色圆圈。如果有人可以提供帮助,我会很高兴。提前致谢。

4

1 回答 1

18

改变顺序,

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

在此处输入图像描述

于 2012-12-21T14:52:23.897 回答