我正试着在另一个圆内画一个更小的圆。这看起来很简单,但我在这方面遇到了麻烦,找不到答案。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大小的黑色圆圈。如果有人能帮上忙,我将不胜感激。提前谢谢。
发布于 2012-12-21 22:52:24
改变顺序,
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);

https://stackoverflow.com/questions/13992094
复制相似问题