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