fullscreen
私が使用TextureView
したボタンを押しながらランドスケープモードでビデオを続行しVideoView
たいSurfaceView
ビューのみがランドスケープである必要があり、アクティビティ全体ではありませんscreenOrientation=landscape in manifest
ポートレートモードです
今何が起こっているのか
これはコードです
if (!isFullScreen()) {
isFullScreen=true;
sizePortait[0]=textureView.getWidth();
sizePortait[1]=textureView.getHeight();
// FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mlayoutVideoTrainig.getHeight(),mlayoutVideoTrainig.getWidth());
textureView.setRotation(90);
textureView.setLayoutParams(params);
adjustAspectRatio(mlayoutVideoTrainig.getHeight(), mlayoutVideoTrainig.getWidth());
}
/**
* Sets the TextureView transform to preserve the aspect ratio of the video.
*/
private void adjustAspectRatio(int videoWidth, int videoHeight) {
int viewWidth = videoWidth;
int viewHeight = videoHeight;
double aspectRatio = (double) videoHeight / videoWidth;
int newWidth, newHeight;
if (viewHeight > (int) (viewWidth * aspectRatio)) {
// limited by narrow width; restrict height
newWidth = viewWidth;
newHeight = (int) (viewWidth * aspectRatio);
} else {
// limited by short height; restrict width
newWidth = (int) (viewHeight / aspectRatio);
newHeight = viewHeight;
}
int xoff = (viewWidth - newWidth) / 2;
int yoff = (viewHeight - newHeight) / 2;
Log.v(TAG, "video=" + videoWidth + "x" + videoHeight +
" view=" + viewWidth + "x" + viewHeight +
" newView=" + newWidth + "x" + newHeight +
" off=" + xoff + "," + yoff);
Matrix txform = new Matrix();
textureView.getTransform(txform);
txform.setScale((float) newWidth / viewWidth, (float) newHeight / viewHeight);
//txform.postRotate(10); // just for fun
txform.postTranslate(xoff, yoff);
textureView.setTransform(txform);
}
XML ファイル
内部フラグメント
<FrameLayout
android:id="@+id/videoSurfaceContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextureView
android:id="@+id/videoSurface"
android:layout_width="match_parent"
android:layout_height="200dp"
/>
</FrameLayout>
<TextView
android:id="@+id/txtHowToObtain"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="@string/how_to_obtain_the_best_mortgage_rate"
android:textColor="@color/myAccentColor"
android:textSize="22sp" />