在Android的全屏幕播放视频

问题描述:

我从相机录制视频,现在我想全屏播放它。但它不适合我。在Android的全屏幕播放视频

我在试这个代码。

<?xml version="1.0" encoding="utf-8"?> 
<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"> 

<VideoView 
    android:id="@+id/camVideoView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerInParent="true" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true"/> 

</RelativeLayout> 

左右两侧都有一些黑色空间。有没有什么方法可以在不丢失宽高比的情况下全屏播放视频。也许像image centerCrop或其他东西。

我读了很多关于*的问题,但没有人解决我的问题。

我看到很多其他玩家在我的设备中全屏播放相同的视频。

我该怎么做?

首先你需要隐藏窗口标题。

// inside onCreate method 
// Hide the window title. 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 

然后像这样添加xml。

<VideoView 
    android:id="@+id/camVideoView" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

而且在mainfest文件集主题活动android:theme="@style/Theme.AppCompat.NoActionBar"

希望这有助于。

<VideoView android:id="@+id/camVideoView" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

你不会有确切的功能,可以说是YouTube API全屏,但确实使用了相对布局这样可能有助于填补屏幕:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<VideoView 
    android:id="@+id/videoViewRelative" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
</VideoView> 

我真的建议得到进入YouTube API以显示视频,功能会更好。 希望它解决你的问题,欢呼声。

根据RelativeLayout,如果设置attr为layout_centerInParent,并且不需要设置layout_centerHorizontal,layout_centerVertical

也许你应该设置此活动的screenOrientation = "landscape"