Android surfaceView填充全屏,亲测 有效

使用环境:

             使用到surfaceView,发现底部总有部分不能填充

使用方法:

获取到surfaceView的实际宽高,将这个宽高通过surfaceView的holder赋值。

代码如下:

  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            int width = mSurfaceView.getMeasuredWidth() / 2;
            //int height = mSurfaceView.getMeasuredHeight();
            SurfaceHolder holder = mSurfaceView.getHolder();
            holder.setFixedSize(width, width);
            //setSurfaceViewCorner(width);
        }
    }

项目中需要用到圆形的surfaceView,代码如下:

  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void setSurfaceViewCorner(final float radius) {
        mSurfaceView.setOutlineProvider(new ViewOutlineProvider() {
            @Override
            public void getOutline(View view, Outline outline) {
                Rect rect = new Rect();
                view.getGlobalVisibleRect(rect);
                int leftMargin = 0;
                int topMargin = 0;
                Rect selfRect = new Rect(leftMargin, topMargin,
                        rect.right - rect.left,
                        rect.bottom - rect.top);
                LogUtil.e("right-->" + (rect.right - rect.left));
                LogUtil.e("bottom-->" + (rect.bottom - rect.top));
                outline.setRoundRect(selfRect, radius);
            }
        });
        mSurfaceView.setClipToOutline(true);
    }

更多讨论,欢迎来询:88627109

祝,工作顺利,永无BUG!

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值