首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何以编程方式在另一个ShapeDrawable中绘制较小的shapeDrawable

如何以编程方式在另一个ShapeDrawable中绘制较小的shapeDrawable
EN

Stack Overflow用户
提问于 2012-12-21 22:40:36
回答 1查看 8.3K关注 0票数 6

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

代码语言:javascript
复制
    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大小的黑色圆圈。如果有人能帮上忙,我将不胜感激。提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-21 22:52:24

改变顺序,

代码语言:javascript
复制
Drawable[] d = {smallerCircle,biggerCircle};

LayerDrawable composite1 = new LayerDrawable(d);

试着这样做

代码语言:javascript
复制
        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);  

票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13992094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档