Android框架的API提供了一套2D绘图API,容许你到画布上呈现本身的自定义图形或修改现有的视图来定制它们的外观和感受。绘制二维图形时,一般你因此选择下面的一种方式:html
1. Drawables:从布局到一个视图对象绘制的图形或动画。你能够简单的图像放到View.java
1)自定义Viewandroid
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:canvas
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 ide