public class CircleView extends View { private Paint mPaint; public CircleView(Context context) { super(context); init(); } public CircleView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { mPaint = new Paint(); mPaint.setColor(Color.RED); mPaint.setStyle(Paint.Style.FILL); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawCircle(getWidth()/2, getHeight()/2, getWidth()/2, mPaint); } }
public class ItemListView extends View { private ListPackage library: android.graphics, java.utilmItems; public ItemListView(Context context) { super(context); init(); } public ItemListView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); init(); } private void init() { mItems = new ArrayList<>(); mItems.add("Item 1"); mItems.add("Item 2"); mItems.add("Item 3"); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setTextSize(50); for (int i = 0; i < mItems.size(); i++) { canvas.drawText(mItems.get(i), 0, i*50, paint); } } }