Onelong

分享知识,与你一起进步......
RSS icon Home icon
  • android 简单图形

    post by onelong / 2010-9-10 1:15 Friday [android]

    package com.hl;

    import android.app.Activity;
    import android.content.Context;
    import android.graphics.Canvas;
    import android.graphics.drawable.ShapeDrawable;
    import android.graphics.drawable.shapes.OvalShape;
    import android.os.Bundle;
    import android.view.View;

    public class SimpleShape extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(new SimpleView(this));
        }
       
        private class SimpleView extends View{
         private ShapeDrawable sd;
      public SimpleView(Context context) {
       super(context);
       setFocusable(true);
       /*
        * RectShape 正方形
        * OvalShape 椭圆形
        * */
       sd = new ShapeDrawable(new OvalShape());//绘制一个正方形
       sd.getPaint().setColor(0xffffee00);//设置颜色
      }
      
      @Override
      protected void onDraw(Canvas canvas) {
       super.onDraw(canvas);
       int x = 10;
       int y = 10;
       int width = 300;
       int height = 50;
       sd.setBounds(x, y, x+width, y+height);//设置边界
       sd.draw(canvas);
      }
      
     }
    }

    引用地址:
     

    我要评论