【问题标题】:Aspect Ratio wrong after onResume()onResume() 后纵横比错误
【发布时间】:2012-05-01 19:21:03
【问题描述】:

我遇到了问题。调用 onResume 后,我的媒体播放器的纵横比变得混乱

private void aspectRatio(MediaPlayer vp)
{

    Integer videoHeight;
    Integer videoWidth;
    //Obtain current video's dimensions for keeping aspect Ration the same on all devices
    videoHeight = vp.getVideoHeight();
    videoWidth = vp.getVideoWidth();

    //Get width of screen
    Integer screenWidth = getWindowManager().getDefaultDisplay().getWidth();
    Integer screenHeight = getWindowManager().getDefaultDisplay().getHeight();

    Log.i("AspectRatio VP WxH", videoHeight.toString() +" x " + videoWidth.toString());
    Log.i("AspectRatio Screen WxH", screenHeight.toString() + " x " + screenWidth.toString());
    ViewGroup.LayoutParams viewParameters = view.getLayoutParams();

    float ratioWidth = (float)screenWidth/(float)videoWidth;
    float ratioHeight = (float)screenHeight/(float)videoHeight;
    float aspectRatio = (float)videoWidth/(float)videoHeight;

    if(ratioWidth>ratioHeight)
    {
        viewParameters.width = (int)(screenHeight * aspectRatio);
        viewParameters.height= screenHeight;
    }
    else if(ratioWidth < ratioHeight)
    {
        viewParameters.width = screenWidth;
        viewParameters.height = (int) (screenHeight / aspectRatio);
    }

    Integer x = viewParameters.width;
    Integer y = viewParameters.height;
    Log.i("Screen", x.toString() + " " + y.toString());
    view.setLayoutParams(viewParameters);
}

这是获取纵横比并将其放入我的surfaceView 的函数。问题是在 onResume() 之后它的宽度比它应该的要小得多。你能看出哪里不对吗?

【问题讨论】:

    标签: android surfaceview aspect-ratio


    【解决方案1】:

    纵横比搞砸了,因为当表面改变时,它又被创建了。现在我更改了它,以便在 onSurfaceChanged 中设置纵横比。它目前可以正常工作。

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 1970-01-01
      • 2013-07-22
      • 2019-11-19
      • 2022-08-19
      • 2012-07-14
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多