2014-11-05 1 views
-2
안드로이드

에 간단한 도형을 그릴 필요 다음과 같지만 작동하지 않습니다.나는 내가 시도</p> <p> 쉐이프 사용 캔버스를 작성, 모양은 이미지 뷰 묘화와 같은 원형 모양에 있어야 안드로이드</p> <p>에서 간단한 도형을 그릴 필요

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; 
    } 
} 
+0

가능 중복 [안드로이드 - 상단 모서리를 둥글게 만와 그리기 (http://stackoverflow.com/questions/8930555/android-drawable-with- 둥근 모서리 - 가기 - 전용) –

답변

0

코드는 아래 작업을 수행 할 것입니다. 하지만 일식 IDE 미리보기에서이를 보지 못할 수도 있습니다. 결과를 디바이스/에뮬레이터에서 실행 체크

<corners 
     android:topLeftRadius="10dp" 
     android:topRightRadius="10dp" 
     android:bottomLeftRadius="0dp" 
     android:bottomRightRadius="0dp"/>