VideoViewを表示する1つのプロジェクトでAndroidSherlockを使用しています。画面の向きが縦向きの場合、ビデオと一部のテキストが表示されます。横向きの場合、フルスクリーンのビデオのみが表示されます。
さて、私の疑問は、向きが縦向きのときに(Sherlockアクションバーの)アルファカラーが表示されるのに、向きが横向きのときにアルファプロパティを変更する(不透明になる)のはなぜですか?
私のonCreate()を以下に示します。
public void onCreate(Bundle savedInstanceState) {
// Makes action bar become translucent, and sets layout of this activity.
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
}
さて、私はrequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY)を使用しています。これにより、アクションバーのアルファ色が可能になります。
向きが変わると、setScreenLayout()を呼び出すonConfigurationChanged()を呼び出します。このメソッドは、ビデオサイズを設定し、アクションバーの背景色を変更します。
/**
* Sets the screen layout, according with the current orientation.
*
* @param isInLandscapeMode
*/
public void setScreenLayout(Boolean isInLandscapeMode) {
// If orientation is landscape.
if (isInLandscapeMode) {
// Hides text of the layout.
mTextScrollView.setVisibility(View.GONE);
// Set the size of the video.
setVideoDimensions((int)Math.floor(mWindowWidth * (1 / WIDESCREEN_RATIO)), mWindowWidth);
// Sets window to full screen.
setWindowToFullScreen();
// Sets action bar background color.
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.bg_translucent_black));
}
// If orientation is portrait.
else {
// Shows text of the layout.
mTextScrollView.setVisibility(View.VISIBLE);
// Set the size of the video.
setVideoDimensions(mWindowWidth, (int)Math.floor(mWindowWidth * WIDESCREEN_RATIO));
// Sets window to normal screen.
setWindowToNormalScreen();
// Sets action bar background color.
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.bg_translucent_black));
}
}
この色はres/colors.xmlで設定されます。
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="bg_translucent_black">#11EEEEEE</color>
</resources>
AndroidManifest.xmlで、android:configChanges = "orientation"プロパティを使用してVideoActivityを設定しました。これにより、向きが変更された場合でもビデオの再生を続行できます。
<!-- Video Activity -->
<activity
android:name=".VideoActivity"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation"
/>
したがって、向きが変更されても、onCreate()は呼び出されません。
何が起こっているのかというと、requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY)は、アクティビティが作成されたときの最初の方向(この場合は縦向き)でのみアルファを許可していると思います。このように、横向きはアルファカラーになりません。確信はないけど。
私が確信しているのは、両方の方向でアクションバーのアルファ色が必要だということです。
私のビデオが両方の方向でアルファカラーを持つことが可能かどうか誰かが知っていますか?