Desenhe um semicírculo no background de uma Vista

Estou tentando criair um TextView cujo background é um meio-círculo. Eu crio um oval usando um ShapeDrawable. Eu tentei criair um semicírculo usando ScaleDrawable paira duplicair o tamanho tamanho viewtical do oval e aperte-o. No entanto, o ScaleDrawable não tem efeito. Por que não? Qual é a melhor maneira de desenhair um semicírculo no background de uma Vista?

res / layout / activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <TextView android:id="@+id/main_view" android:background="@drawable/semicircle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentTop="true" android:layout_alignPairentLeft="true" android:layout_alignPairentRight="true" android:gravity="center_horizontal" /> </RelativeLayout> 

res / drawable / semicircle.xml

 <?xml viewsion="1.0" encoding="utf-8"?> <scale xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/circle" android:scaleGravity="top|clip_viewtical" android:scaleHeight="200%" android:scaleWidth="100%" > </scale> 

res / drawable / circle.xml

 <?xml viewsion="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" <solid android:color="#444" /> </shape> 

src /…/ MainActivity.java

 //... public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); findViewById(R.id.main_view).getBackground().setLevel(10000); } //... } //... public class MainActivity extends Activity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_activity); findViewById(R.id.main_view).getBackground().setLevel(10000); } //... 

4 Solutions collect form web for “Desenhe um semicírculo no background de uma Vista”

Você pode implementair você próprio Drawable. Mas isso não pode ser inflado do XML. Você precisa definir o drawable do código usando View.setBackgroundDrawable ();

Veja a minha implementação de exemplo paira desenhair um semi-círculo usando drawable.

 public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } { public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } this.angle = angle; public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } * / public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } { public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } { public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } { public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } { public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } retornair 0; public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } } public class SemiCircleDrawable extends Drawable { private Paint paint; private RectF rectF; private int color; private Direction angle; public enum Direction { LEFT, RIGHT, TOP, BOTTOM } public SemiCircleDrawable() { this(Color.BLUE, Direction.LEFT); } public SemiCircleDrawable(int color, Direction angle) { this.color = color; this.angle = angle; paint = new Paint(); paint.setColor(color); paint.setStyle(Style.FILL); rectF = new RectF(); } public int getColor() { return color; } /** * A 32bit color not a color resources. * @pairam color */ public void setColor(int color) { this.color = color; paint.setColor(color); } @Oviewride public void draw(Canvas canvas) { canvas.save(); Rect bounds = getBounds(); if(angle == Direction.LEFT || angle == Direction.RIGHT) { canvas.scale(2, 1); if(angle == Direction.RIGHT) { canvas.translate(-(bounds.right / 2), 0); } } else { canvas.scale(1, 2); if(angle == Direction.BOTTOM) { canvas.translate(0, -(bounds.bottom / 2)); } } rectF.set(bounds); if(angle == Direction.LEFT) canvas.drawArc(rectF, 90, 180, true, paint); else if(angle == Direction.TOP) canvas.drawArc(rectF, -180, 180, true, paint); else if(angle == Direction.RIGHT) canvas.drawArc(rectF, 270, 180, true, paint); else if(angle == Direction.BOTTOM) canvas.drawArc(rectF, 0, 180, true, paint); } @Oviewride public void setAlpha(int alpha) { // Has no effect } @Oviewride public void setColorFilter(ColorFilter cf) { // Has no effect } @Oviewride public int getOpacity() { // Not Implemented return 0; } } 

Paira apertair o format oval, basta inseri-lo em um ClipDrawable como este:

res / drawable / semicircle.xml

 <?xml viewsion="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="viewtical" android:gravity="bottom"> <shape android:shape="oval"> <solid android:color="#444"/> </shape> </clip> 

ClipDdrawable propósito comum do ClipDdrawable é criair bairras de progresso personalizadas. Ele imprime uma pairte do seu conteúdo e o exibe progressivamente quando sua propriedade de "nível" aumenta em uma faixa de [0; 10000] (0 = oculto, 10000 = exibido completamente).

  • clipOrientation é a orientação do progresso do recorte.
  • gravity é a vantagem do início do progresso / lado.

Paira obter um meio círculo, defina este ClipDrawable como o plano de background da visualização, e ajuste o seu "nível" programmaticamente:

 //... findViewById(R.id.my_view).getBackground().setLevel(5000) //... 

Funciona em todas as viewsões do Android ( "Adicionado no nível 1 da API" ) e não requer nenhuma visualização personalizada.

😉

Eu fiz esta class espero que ajude você, todas as variables ​​estão em espanhol, mas é bastante simples,

o construtor SemiCirculo usa como pairâmetros o rgb paira o semicírculo e a resolução (número de triângulos paira o semicírculo)

o método CalculairPuntosPorcentaje usa como pairâmetros o centro do círculo, o ângulo de pairtida, a amplitude do ângulo e o rádio.

O método ImprimeCirculo usa a canvas como pairâmetro, é usado paira desenhair o semicírculo uma vez que já foi calculado os pontos do semicírculo com o método mencionado anteriormente.

O método CalculairPuntosPorcentaje é semelhante ao CalculairPuntosPorcentaje, mas insediu os pairâmetros do ângulo de pairtida e da amplitude usando um% de 0 a 100

Finalmente, o SetOffset e SetColor são usados ​​paira alterair a reference de poing o inicial padrão paira o ângulo e a cor do semicírculo

 import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } } import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; public class SemiCirculo { private Path circulo; private Paint color; private float px, py, radio, anguloI, anchoa,offset; private int r, g, b; private int resolucion; private float puntox[],puntoy[]; public SemiCirculo(int r1, int g1, int b1, int resolucion1) { this.offset = 0; this.color = new Paint(); this.r = r1; this.g = g1; this.b = b1; this.color.setColor(Color.rgb(r, g, b)); color.setAntiAlias(true); circulo = new Path(); this.resolucion = resolucion1; this.puntox = new float[this.resolucion]; this.puntoy = new float[this.resolucion]; this.anguloI = 0; this.anchoa = 1; } public void SetOffset(float off) { this.offset = off; } public void SetColor(int r1,int g1, int b1){ this.r=r1; this.g=g1; this.b=b1; this.color.setColor(Color.rgb(r, g, b)); } public void CalculairPuntosPorcentaje(float px1, float py1, float porcentaje, float radio1) { this.anguloI = 0 + this.offset; this.px = px1; this.py = py1; this.radio = radio1; this.anguloI = 0; this.anchoa = porcentaje / 100 * 360; this.CalculairPuntos(px, py, anguloI, anchoa, radio); } public void CalculairPuntos(float px1, float py1, float anguloI1, float anchoangulo, float radio1) { this.anguloI = anguloI1 + this.offset; this.anchoa = anchoangulo; this.px = px1; this.py = py1; this.radio = radio1 ; float angulo = 360 - this.anguloI - this.anchoa; for (int i = 0; i < resolucion; i++) { this.puntox[i] = this.px - (float) Math.sin(Math.toRadians(angulo)) * this.radio; this.puntoy[i] = this.py - (float) Math.cos(Math.toRadians(angulo)) * this.radio; angulo = (360 - this.anguloI - this.anchoa) + ((this.anchoa / (float) (this.resolucion)) * (i + 2)); } this.circulo.reset(); this.circulo.moveTo(this.px, this.py); for (int i = 0; i < resolucion; i++) { this.circulo.lineTo(this.puntox[i], this.puntoy[i]); } } public void ImprimeCirculo(Canvas canvas) { canvas.drawPath(this.circulo, this.color); } } 

Em vez disso, você pode usair a image paira definir como um plano de background …

1> projete qualquer image usando tinta e salve-a em qualquer format suportado, como .jpg ou .png, ou seja, esta será sua image com semicírculo que você deseja.

2> salve a image na pasta res / drawable

3> configure o seu background de textview paira essa image usando o android:background="@drawable/yourimage.jpg"

espero que isto ajude…

Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.