您可以View
通过覆盖onDraw
that 的方法在 Android 中自定义 a View
。
您可能会考虑的是:
@Override
protected void onDraw(Canvas canvas) {
// paint a line through the centre
Paint paint = new Paint();
canvas.drawLine(0, canvas.getWidth(), canvas.getHeight()/2,
canvas.getHeight()/2, paint);
super.onDraw(canvas);
}
这将通过View
(在您的情况下为 a TextView
)的中心画一条线。您可以对 10%/90% 的着色使用相同的方法。
例如。
@Override
protected void onDraw(Canvas canvas) {
// paint a region blue
Paint paint = new Paint();
paint.setColor(Color.BLUE);//or whatever colour you want
canvas.drawRect(0, canvas.getHeight()/10, canvas.getWidth(),
canvas.getHeight(), paint)
super.onDraw(canvas);
}
Draw rect 接受参数:
canvas.drawRect(left, top, right, bottom, paint)
还有其他选择,您可以传入实际的绘图 Rectangle 等。