Fill remaining space with fixed aspect ratio surfaceview

前端 未结 4 553
生来不讨喜
生来不讨喜 2020-12-11 03:14

I\'d like to layout a view like the following, but I\'m not sure how to go about doing so:

  • At the bottom of the screen is a regular view, with a fixed size (fi
4条回答
  •  时光说笑
    2020-12-11 04:04

    To set the size of the SurfaceView you should use:

        // Set surfaceview size in px
    private void setVideoSize(int width, int height) {
        LayoutParams params = (LayoutParams) mYourSurfaceView.getLayoutParams();
        params.height = height;
        params.width = width;
        mYourSurfaceView.setLayoutParams(params);
    }
    

    And if you want to know the size of the screen:

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
    int width = display.getWidth(); 
    int heigth = display.getHeight(); 
    

    Hope this helps

提交回复
热议问题