-2

I need to draw a simple shape in android

The shape needs to be in circle shape as ImageView drawable, create a ShapeDrawable use canvas

I tried the following but not working

    public class MyButton extends ImageButton {
    private Drawable iconDrawable;

    public MyButton(Context context) {
        super(context);
    }

    public MyButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        setImageDrawable(getIconDrawable());
    }

    /**
     * just draw a simple circle
     *
     * @return
     */
    public Drawable getIconDrawable() {

        Shape shape = new Shape() {
            @Override public void draw(Canvas canvas, Paint paint) {
                paint.setColor(Color.RED);
                paint.setStyle(Paint.Style.FILL);
                canvas.drawCircle(0, 0, 20, paint);
            }
        };

        ShapeDrawable drawable = new ShapeDrawable(shape);

        return drawable;
    }
}
LiFei
  • 407
  • 3
  • 8
  • possible duplicate of [Android - drawable with rounded corners at the top only](http://stackoverflow.com/questions/8930555/android-drawable-with-rounded-corners-at-the-top-only) – M D Nov 05 '14 at 12:46

1 Answers1

0

below code will do the job. But you may fail to see it in the eclipse IDE preview. Run it in device/emulator and check the result

 <corners
        android:topLeftRadius="10dp"
        android:topRightRadius="10dp"
        android:bottomLeftRadius="0dp" 
        android:bottomRightRadius="0dp"/>
Aun
  • 1,883
  • 1
  • 17
  • 26