. , , . :
https://developer.android.com/guide/topics/graphics/2d-graphics.html
:
package com.example;
import android.content.Context;
import android.graphics.*;
import android.util.AttributeSet;
import android.view.View;
public class CustomView extends View {
Bitmap bitmap;
Paint paint;
Rect dst;
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public CustomView(Context context) {
super(context);
init();
}
void init() {
paint = new Paint();
paint.setStyle(Paint.Style.FILL_AND_STROKE);
bitmap = Bitmap.createBitmap(4, 1, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
paint.setColor(Color.parseColor("#c43134"));
c.drawRect(0, 0, 1, 1, paint);
paint.setColor(Color.parseColor("#b3632e"));
c.drawRect(1, 0, 2, 1, paint);
paint.setColor(Color.parseColor("#ab2463"));
c.drawRect(2, 0, 3, 1, paint);
paint.setColor(Color.parseColor("#8e9e34"));
c.drawRect(3, 0, 4, 1, paint);
}
protected void onDraw(Canvas canvas) {
canvas.drawBitmap(bitmap, (Rect) null, dst, paint);
}
protected void onSizeChanged(int x, int y, int ox, int oy) {
dst = new Rect(0, 0, x, y);
}
}
, 2d, , , .
drawBitmap() onDraw() , , .
: :

: , . .
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.example.CustomView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>