当我处于全屏模式时,无法在屏幕的右下角绘制矩形,这意味着没有状态栏可见,也没有导航栏可见
Display mdisp = getWindowManager().getDefaultDisplay();
Point mdispSize = new Point();
mdisp.getSize(mdispSize);
int maxX = mdispSize.x;
int maxY = mdispSize.y;
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawRect(0, maxY-pixel, pixel, MaxY);
}
答案 0 :(得分:0)
这是在Kotlin中,但它可以向您展示如何实现此目标:
class MyView(context: Context, attributeSet: AttributeSet) : View(context, attributeSet) {
private var mHeight = 0
private var mWidth = 0
override fun onDraw(canvas: Canvas?) {
canvas?.drawRect(mWidth-100, mHeight-100, mWidth, mHeight)
}
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
mHeight = bottom - top
mWidth = right - left
}
}