2012-05-01 16 views
0

問題があります。 onResumeが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()の後に、その幅が想定されるよりもずっと小さいことです。何が間違っているのを見ることができますか?

答えて

0

表面が変更されたときに再び作成されたため、アスペクト比が乱雑になりました。今度は、アスペクト比がonSurfaceChangedにも設定されるように変更しました。現在問題なく動作しています。

関連する問題