gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:25:17 26 4
gpt4 key购买 nike

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

    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。如果有人可以提供帮助,我会很高兴。提前致谢。

最佳答案

改变顺序,

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

enter image description here

关于android - 如何以编程方式在另一个 shapeDrawable 中绘制一个较小的 ShapeDrawable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13992094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com