如何更改自定义surfaceView的宽度和高度

Kam*_*mar 10 android

如何更改自定义SurfaceView宽度和高度.这可能吗?

小智 20

我有同样的问题.但这绝对有用,只需要检查你设置的是什么类型的LaoutParams.我有同样的问题,因为我使用FrameLaoutPrams而不是LayoutParams.我需要像这样设置它:

    android.widget.FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(width, height);
    surface.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)


ana*_*ass 5

这是正确的方法:

surfaceView.getHolder().setFixedSize(width, height);
Run Code Online (Sandbox Code Playgroud)


Ads*_*Ads 2

setLayoutParams(new LayoutParams(宽度,高度)); 我希望这会起作用