2017-07-18 162 views
1

我從相機錄製視頻,現在我想全屏播放它。但它不適合我。在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或其他東西。

我讀了很多關於stackoverflow的問題,但沒有人解決我的問題。

我看到很多其他玩家在我的設備中全屏播放相同的視頻。

我該怎麼做?

回答

2

首先你需要隱藏窗口標題。

// 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"

希望這有助於。

0
<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"> 
0

你不會有確切的功能,可以說是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以顯示視頻,功能會更好。 希望它解決你的問題,歡呼聲。

-1

根據RelativeLayout,如果設置attr爲layout_centerInParent,並且不需要設置layout_centerHorizontal,layout_centerVertical

也許你應該設置此活動的screenOrientation = "landscape"