Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android VideoView不能填满整个屏幕_Android - Fatal编程技术网

Android VideoView不能填满整个屏幕

Android VideoView不能填满整个屏幕,android,Android,我正在为我的应用程序播放一段简短的介绍视频。因为这是一个游戏,首先我创建了一个主题来隐藏动作栏并全屏显示 styles.xml: <style name="AppTheme.NoTitleBar" parent="AppTheme"> <item name="android:windowNoTitle">true</item> </style> <style name="AppTheme.NoTitleBar.Fullscreen"

我正在为我的应用程序播放一段简短的介绍视频。因为这是一个游戏,首先我创建了一个主题来隐藏动作栏并全屏显示

styles.xml:

<style name="AppTheme.NoTitleBar" parent="AppTheme">
    <item name="android:windowNoTitle">true</item>
</style>

<style name="AppTheme.NoTitleBar.Fullscreen" parent="AppTheme.NoTitleBar">
    <item name="android:windowFullscreen">true</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity" >

    <VideoView
        android:id="@+id/videoView_intro"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" />

</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    VideoView v = (VideoView) findViewById(R.id.videoView_intro);
    v.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.intro));
    /* This line had a code snippet for event handling, unrelated to this question */
    v.start();
}
    <activity
        android:name="org.package.name.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
最后,我通过以下代码播放了视频:

MainActivity.java:

<style name="AppTheme.NoTitleBar" parent="AppTheme">
    <item name="android:windowNoTitle">true</item>
</style>

<style name="AppTheme.NoTitleBar.Fullscreen" parent="AppTheme.NoTitleBar">
    <item name="android:windowFullscreen">true</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity" >

    <VideoView
        android:id="@+id/videoView_intro"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" />

</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    VideoView v = (VideoView) findViewById(R.id.videoView_intro);
    v.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.intro));
    /* This line had a code snippet for event handling, unrelated to this question */
    v.start();
}
    <activity
        android:name="org.package.name.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
我成功地播放了视频,但视频视图的底部有一小部分空白。我假设它与通知栏的高度相匹配。我怎样才能去掉那个边距

编辑:我不知道是否需要这些信息,但活动是强制进行的。此外,我针对API级别8的所有android设备,因此该解决方案必须与API级别8兼容

AndroidManifest.xml:

<style name="AppTheme.NoTitleBar" parent="AppTheme">
    <item name="android:windowNoTitle">true</item>
</style>

<style name="AppTheme.NoTitleBar.Fullscreen" parent="AppTheme.NoTitleBar">
    <item name="android:windowFullscreen">true</item>
</style>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity" >

    <VideoView
        android:id="@+id/videoView_intro"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="0dp"
        android:layout_marginTop="0dp" />

</RelativeLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    VideoView v = (VideoView) findViewById(R.id.videoView_intro);
    v.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.intro));
    /* This line had a code snippet for event handling, unrelated to this question */
    v.start();
}
    <activity
        android:name="org.package.name.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

您的最佳选择可能是创建自己的VideoView子类,重写该方法,并让其获取屏幕尺寸,修改VideoView高度/宽度以匹配设备的正确高度/宽度

如果您不希望这样做,那么您的其他更容易的选项是在全屏对话框中启动视频,或者您可以将LayoutParams设置为运行时生成的静态大小:

VideoView v = (VideoView) findViewById(R.id.videoView_intro);
v.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.intro));

DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    v.setLayoutParams(new LayoutParams(metrics.widthPixels, metrics.heightPixels));

v.start();

好吧,当我想到这个想法的时候,我想我变成了一个傻瓜

问题不在于通知栏。相反,它是关于视频的纵横比

视频大小为480×272。它的纵横比约为1.7647。另一方面,Galaxy Nexus的可用屏幕尺寸为1184×720,纵横比约为1.6444。因此,视频基本上比屏幕“长”

我没有找到原因,因为: 1) 奇怪的是,边距的高度几乎与通知栏的高度一致 2) 因为视频是一个比手机屏幕更窄的系统的记录,我不相信这会是原因。(编码器破坏了假定的纵横比。)

最后,我应该研究一下这篇文章:


教训是,不要过多地介入你的假设。

我想最快的方法是用负值应用底部边距。尝试it@Maver1ck尝试了android:layout_marginBottom=“-8dp”。结果是否定的。事实上,我的问题的原因是在其他地方,但您的回答有助于理解系统功能。但是,由于代码引入了编程模糊性,我建议进行修改。@ArleCamille哦,您可能已经从另一个包导入了LayoutParams。我不确定我是否正确地接受了编辑…嗨,你真的应该解释为什么你的答案比接受的好。尤其是在发布这样一个老答案的时候。实际上我不知道在哪里为这个老答案写评论。。所以,我补充说,作为新的回答者,你需要赢得更多的声誉才能发表评论。
VideoView v = (VideoView) findViewById(R.id.videoView_intro);
v.setVideoURI(Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.intro));

DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    v.setLayoutParams(new LayoutParams(metrics.widthPixels, metrics.heightPixels));

v.start();`enter code here`

this code worked correctly