我正在爲我的Android應用創建登錄屏幕,並且想知道如何將視頻用作背景而不是具有圖像或簡單的顏色?設置視頻爲背景
我想讓它與Spotify/Bible應用登錄屏幕類似,他們有一個視頻播放,並且您有按鈕可以登錄或註冊。
圖片 -
(點擊圖片放大)
我正在爲我的Android應用創建登錄屏幕,並且想知道如何將視頻用作背景而不是具有圖像或簡單的顏色?設置視頻爲背景
我想讓它與Spotify/Bible應用登錄屏幕類似,他們有一個視頻播放,並且您有按鈕可以登錄或註冊。
圖片 -
(點擊圖片放大)
首先做出新XML
並添加VideoView
裏面:
my_video_background.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" />
</RelativeLayout>
然後包括你的主要佈局在這個文件中有Buttons
,讓我們說:
splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#29000000">
<include layout="@layout/my_video_background" />
<!--Like Spotify image-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:src="@android:drawable/ic_dialog_map" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<Button
android:id="@+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#FF2D2D2D"
android:text="LOG IN"
android:textColor="@android:color/white" />
<Button
android:id="@+id/signUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="#FF669900"
android:text="SIGN IN"
android:textColor="@android:color/white" />
</LinearLayout>
</RelativeLayout>
這就是它!
我認爲視圖尋呼機需要將其添加到具有一些透明背景的佈局 –
在VideoView所以視頻將從左到右全屏擴展添加: android:layout_alignParentEnd =「true」 android:layout_alignParentStart =「true 「 –
您只需要幾個步驟即可將視頻設置爲應用程序的背景。
VideoView videoview = (VideoView) findViewById(R.id.videoview); Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.test); videoview.setVideoURI(uri); videoview.start();我已經解釋瞭如何將視頻在Android中創建JOOX登錄屏幕,它看起來或多或少像Spotify應用程序。隨時檢查出來,並讓我知道,如果它可以幫助:)
這是工作,謝謝你的兄弟! –
NatureDevil答案和視頻是偉大的,但如果你點擊一個按鈕,打開像一個新的活動2個東西不見了第一唱起來,並決定單擊後退箭頭在設備上,主屏幕會給黑屏,因爲視頻將不會重新啓動,所以你需要添加此
@Override
protected void onResume() {
super.onResume();
// to restart the video after coming from other activity like Sing up
mVideoView.start();
}
其他東西了VideoView伸展從左右全屏添加:
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
你解決了這個問題嗎? – exequielc