【发布时间】:2012-05-29 19:13:09
【问题描述】:
我在一个展示 VideoView 的项目中使用 Android Sherlock。当屏幕方向为纵向时,会显示视频和一些文本。当是横屏时,只显示全屏视频。
好吧,我的疑问是:为什么当方向为纵向时会显示(Sherlock Action Bar 的)alpha 颜色,而当方向为横向时会改变它的 alpha 属性(变得不透明)?
我的 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),它允许操作栏中的 alpha 颜色。
当方向改变时,我调用 onConfigurationChanged(),它调用 setScreenLayout()。此方法设置视频大小并更改操作栏背景颜色。
/**
* 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) 仅在创建活动时(在本例中为纵向)允许 alpha 在第一个方向。这样,横向不会变成 alpha 颜色。但我不确定。
我确定我需要操作栏在两个方向上的 alpha 颜色。
有人知道我的视频是否可以在两个方向上都有 alpha 颜色吗?
【问题讨论】:
标签: android