我正在为我的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