2013年12月31日

Android View

自定義view類別
透過class繼承view這個類別

class MainActivityView extends View {
private ShapeDrawable mDrawable;
private Paint mPaint;

public MainActivityView(Context context) {
super(context);
// TODO Auto-generated constructor stub
int height = 100;
int width = 100;
mDrawable = new ShapeDrawable(new RectShape());
mDrawable.setBounds(0, 0, width, height);
mPaint = mDrawable.getPaint();
mPaint.setColor(Color.argb(255, 0, 0, 0));
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
mDrawable.draw(canvas);
}

}

沒有留言:

張貼留言