我是新手,我正在尝试创建一个可以从网址播放视频的简单应用程序。我能够在我的应用程序中成功播放视频,但我希望它自动旋转,当我点击全屏按钮时隐藏动作栏标题和全屏。
这是我的清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="htantruc.videotest">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen">
<activity android:name=".video"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".VideoViewActivity"
android:configChanges="orientation|screenSize"></activity>
</application>
</manifest>
和我的 xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".VideoViewActivity"
android:theme="@style/CustomActivityThemeNoActionBar">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="250dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true">
<com.github.rtoshiro.view.video.FullscreenVideoLayout
android:id="@+id/videoview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
</RelativeLayout>
答案 0 :(得分:0)
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
如果您不在活动中,可以通过WINDOW_SERVICE获取默认显示:
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
在引入getSize之前(在API级别13中),您可以使用现已弃用的getWidth和getHeight方法:
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth(); // deprecated
int height = display.getHeight(); // deprecated
如何设置宽度和高度
videoView.getHolder().setFixedSize(width, height);
在您的活动和onConfigurationChanged()
答案 1 :(得分:0)
1 - 尝试使用自动旋转 - 将这些添加到Manifest:
机器人:configChanges = “取向|屏幕尺寸”
机器人:screenOrientation = “纵向”
答案 2 :(得分:0)
请按照以下方式点击全屏按钮:
public void onFullScreenClick(View v)
{
getActionbar().hide();
getActionbar().show();
//doesn't work then try
//getSupportActionBar().hide();
//getSupportActionBar().show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// For Landscape above line and For Portrait find Below
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
注意:不要忘记添加行
机器人:configChanges =&#34;取向|屏幕尺寸&#34;在清单文件中
希望这会起作用