2011-04-11 17 views
0

我繪製了一個圖形對象,例如矩形。我想在矩形的每個角落寫一些文字。如何實現這一目標?將文本值放置在所需的位置

private static class SimpleView extends View { 
    private ShapeDrawable mDrawable = new ShapeDrawable(); 

    public SimpleView(Context context) { 
     super(context); 
     setFocusable(true); 
     this.mDrawable = new ShapeDrawable(new RectShape()); 
     this.mDrawable.getPaint().setColor(0xFF0F00FF); 


} 

      @Override 
     protected void onDraw(Canvas canvas) { 
      int x1 = 50; 
      int y1 = 150; 
      int width = 400; 
      int height = 50; 
      this.mDrawable.setBounds(x1, y1, x1 + width, y1 + height); 
      this.mDrawable.draw(canvas); 

      int x = 0; 
      int y = 0; 
      Paint paint = new Paint(); 
      paint.setStyle(Paint.Style.FILL); 

+0

PLZ,提供了一個例子。 – Macarse 2011-04-11 13:04:32

+0

你使用什麼組件,畫布? – 2011-04-11 13:05:05

+0

是的,我正在使用畫布 – m4n07 2011-04-11 13:06:37

回答

0

使用canvas.drawText與角的座標,並與Paint設定在適當的定位。即您可以在每個角落繪製文本,右角具有paint.align = RIGHT,左角具有paint.align = LEFT。這樣,文字被畫在廣場的一側。

相關問題