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

问题描述 投票:0回答:1

我处于全屏模式时无法在屏幕的底角绘制矩形表示没有可见的状态栏,也看不到导航栏

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

android android-canvas ondraw
1个回答
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
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.