使用环境:
使用到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!