Android y SurfaceView. Tamaño equivocado

Tengo algunos problemas con el reajuste de tamaño de SurfaceView en Android 2.3. versiones. Estoy trabajando con reproductor de video Necesito cambiar el tamaño de mi SurfaceView cuando el tamaño del marco de video no coincide con el tamaño de la superficie. Tengo el fragmento con SurfaceView dentro de él. Fragmento no coincide con la pantalla completa, sólo una parte de ella. Para las versiones de Android 4 todo está bien, pero en Android 2.3. después de cambiar de tamaño mi SurfaceView es más grande que su padre FrameLayout. No tengo ideas de por qué esto está sucediendo.

Aquí está la interfaz que permite el tamaño de vídeo init

/** * This method is called by native vout to request a surface resize when frame size doesn't match surface size. * @param width Frame width * @param height Frame height * @param visible_width Visible frame width * @param visible_height Visible frame height * @param sar_num Surface aspect ratio numerator * @param sar_den Surface aspect ratio denominator */ void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den); //This method is an implementation of Interface @Override public void setSurfaceSize(int width, int height, int visible_width, int visible_height, int sar_num, int sar_den) { if (width * height == 0) return; // store video size mVideoHeight = height; mVideoWidth = width; mVideoVisibleHeight = visible_height; mVideoVisibleWidth = visible_width; mSarNum = sar_num; mSarDen = sar_den; Message msg = mHandler.obtainMessage(SURFACE_SIZE); mHandler.sendMessage(msg); } 

Y el segundo – cambiar mi tamaño de SurfaceView.

  private void changeSurfaceSize() { int sw; int sh; // get screen size if (mPresentation == null) { Log.d("MyLog", "Presentation is null"); sw = ((Activity)mainActivity).getWindow().getDecorView().getWidth(); sh = ((Activity)mainActivity).getWindow().getDecorView().getHeight(); } else { Log.d("MyLog", "Presentation is not null"); sw = mPresentation.getWindow().getDecorView().getWidth(); sh = mPresentation.getWindow().getDecorView().getHeight(); } double dw = sw, dh = sh; boolean isPortrait; if (mPresentation == null) { // getWindow().getDecorView() doesn't always take orientation into account, we have to correct the values isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT; } else { isPortrait = false; } if (sw > sh && isPortrait || sw < sh && !isPortrait) { dw = sh; dh = sw; } // sanity check if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) { Log.e(TAG, "Invalid surface size"); return; } // compute the aspect ratio double ar, vw; double density = (double)mSarNum / (double)mSarDen; if (density == 1.0) { /* No indication about the density, assuming 1:1 */ vw = mVideoVisibleWidth; ar = (double)mVideoVisibleWidth / (double)mVideoVisibleHeight; } else { /* Use the specified aspect ratio */ vw = mVideoVisibleWidth * density; ar = vw / mVideoVisibleHeight; } // compute the display aspect ratio double dar = dw / dh; switch (mCurrentSize) { case SURFACE_BEST_FIT: if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_FIT_HORIZONTAL: dh = dw / ar; break; case SURFACE_FIT_VERTICAL: dw = dh * ar; break; case SURFACE_FILL: break; case SURFACE_16_9: ar = 16.0 / 9.0; if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_4_3: ar = 4.0 / 3.0; if (dar < ar) dh = dw / ar; else dw = dh * ar; break; case SURFACE_ORIGINAL: dh = mVideoVisibleHeight; dw = vw; break; } SurfaceView surface; SurfaceView subtitlesSurface; SurfaceHolder surfaceHolder; SurfaceHolder subtitlesSurfaceHolder; FrameLayout surfaceFrame; if (mPresentation == null) { surface = mSurface; subtitlesSurface = mSubtitlesSurface; surfaceHolder = mSurfaceHolder; subtitlesSurfaceHolder = mSubtitlesSurfaceHolder; surfaceFrame = mSurfaceFrame; } else { surface = mPresentation.mSurface; subtitlesSurface = mPresentation.mSubtitlesSurface; surfaceHolder = mPresentation.mSurfaceHolder; subtitlesSurfaceHolder = mPresentation.mSubtitlesSurfaceHolder; surfaceFrame = mPresentation.mSurfaceFrame; } // force surface buffer size surfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); subtitlesSurfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); // set display size LayoutParams lp = surface.getLayoutParams(); lp.width = (int) Math.ceil(dw * mVideoWidth / mVideoVisibleWidth); lp.height = (int) Math.ceil(dh * mVideoHeight / mVideoVisibleHeight); surface.setLayoutParams(lp); subtitlesSurface.setLayoutParams(lp); // set frame size (crop if necessary) lp = surfaceFrame.getLayoutParams(); lp.width = (int) Math.floor(dw); lp.height = (int) Math.floor(dh); surfaceFrame.setLayoutParams(lp); surface.invalidate(); subtitlesSurface.invalidate(); } 

¿Alguien tiene alguna idea, por qué podría suceder así? ¡Estaré muy alegre para cualquier ayuda !!! ¡Gracias!

FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.