无法在屏幕的下角绘制矩形

时间:2019-02-19 10:56:11

标签: android android-canvas ondraw

当我处于全屏模式时,无法在屏幕的右下角绘制矩形,这意味着没有状态栏可见,也没有导航栏可见

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);
           }

通过使用此代码,我无法将该矩形放在底角,该矩形始终显示在该区域上方,该区域是导航栏的保留区域。 corner

1 个答案:

答案 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
    }
}