Android框架的API提供了一套2D绘图API,允许你到画布上呈现自己的自定义图形或修改现有的视图来定制它们的外观和感觉。绘制二维图形时,通常你所以选择下面的一种方式:
1. Drawables:从布局到一个视图对象绘制的图形或动画。你可以简单的图像放到View.
1)自定义View
public class CustomDrawableView extends View {
private ShapeDrawable mDrawable;
public CustomDrawableView(Context context) {
super(context);
int x = 10;
int y = 10;
int width = 300;
int height = 50;
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
}
protected void onDraw(Canvas canvas) {
mDrawable.draw(canvas);
}
}
2)Activity:
CustomDrawableView mCustomDrawableView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCustomDrawableView = new CustomDrawableView(this);
setContentView(mCustomDrawableView);
}
3)XML
<com.example.shapedrawable.CustomDrawableView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
2. Canvas:直接把图像画到Canvas上。
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
http://developer.android.com/guide/topics/graphics/2d-graphics.html