gpt4 book ai didi

java - 为什么我恢复应用程序后 SurfaceView 会被剪切?

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:07 25 4
gpt4 key购买 nike

如果我使用 Android L 设备并恢复我的应用程序,SurfaceView 将被剪切。

发生条件详情如下:
- 使用Android L(原来是L,未更新为L)
- SurfaceView 大于显示屏。
- SurfaceView 的左上角更靠近显示屏的左侧或顶部。
- 从后台应用程序列表恢复应用程序,而不是应用程序列表中的图标。

我尝试重置大小、重力、剪辑边界等,但是没有效果。
我想修复SurfaceView的切口,你没有什么想法吗?

示例代码如下:

[ Activity ]

public class ViewTestActivity extends Activity {

private DrawSurfaceView mDrawSurfaceView;
private int overDispW;
private int overDispH;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point dispP = new Point();
display.getSize(dispP);
overDispW = (int) (dispP.x * 1.5);
overDispH = (int) (dispP.y * 1.5);

FrameLayout.LayoutParams overSizeParams = new FrameLayout.LayoutParams(overDispW, overDispH);

//If gravity is Gravity.LEFT|Gravity.TOP, there is no cut.
overSizeParams.gravity = Gravity.CENTER;

mDrawSurfaceView = new DrawSurfaceView(this);

setContentView(mDrawSurfaceView, overSizeParams);
}
}

[SurfaceView]

public class DrawSurfaceView extends SurfaceView implements SurfaceHolder.Callback{

private Paint mPaintRed;
private Paint mPaintBlue;
private Paint mPaintGreen;
private Paint mPaintYellow;
private SurfaceHolder mHolder;

public DrawSurfaceView(Context context) {
super(context);

mPaintRed = new Paint();
mPaintRed.setColor(Color.argb(255, 255, 0, 0));

mPaintBlue = new Paint();
mPaintBlue.setColor(Color.argb(255, 0, 0, 255));

mPaintGreen = new Paint();
mPaintGreen.setColor(Color.argb(255, 0, 255, 0));

mPaintYellow = new Paint();
mPaintYellow.setColor(Color.argb(255, 255, 255, 0));

mHolder = getHolder();
mHolder.setFormat(PixelFormat.RGBA_8888);
mHolder.addCallback(this);
}

public void onDraw(Canvas canvas){
super.onDraw(canvas);
drawRect(canvas);
}

private void drawRect(Canvas canvas) {
int w = canvas.getWidth();
int h = canvas.getHeight();
canvas.drawColor(Color.TRANSPARENT, Mode.CLEAR);
canvas.drawRect(0, 0, w/2, h/2, mPaintRed);
canvas.drawRect(w/2, h/2, w, h, mPaintBlue);
canvas.drawRect(w/2, 0, w, h/2, mPaintGreen);
canvas.drawRect(0, h/2, w/2, h, mPaintYellow);
}

public void doDraw(){
Canvas canvas = mHolder.lockCanvas();
if(canvas != null){
drawRect(canvas);
mHolder.unlockCanvasAndPost(canvas);
}
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
doDraw();
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
doDraw();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}

最佳答案

右侧 View 已被剪切。

enter image description here

关于java - 为什么我恢复应用程序后 SurfaceView 会被剪切?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33275128/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com