Ala*_*lan 6 android drawing dynamic shapes drawable
我试图在另一个圆圈内绘制一个较小的圆圈.这似乎很简单,但我遇到了麻烦,无法找到答案.我使用的代码是:
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,});
Run Code Online (Sandbox Code Playgroud)
但那不起作用,会发生的是,较小的圆圈会变得像较大的圆圈一样大.所以唯一显示的是黑色圆圈,大圆圈的大小.如果有人可以提供帮助,我会帮助你.提前致谢.
Tal*_*lha 18
改变顺序,
Drawable[] d = {smallerCircle,biggerCircle};
LayerDrawable composite1 = new LayerDrawable(d);
Run Code Online (Sandbox Code Playgroud)
试试这样
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);
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
8094 次 |
| 最近记录: |