【发布时间】:2015-11-01 02:59:09
【问题描述】:
我正在为我的 Android 应用制作登录屏幕,并且想知道如何使用视频作为背景而不是使用图像或简单的颜色?
我想让它类似于 Spotify / 圣经应用程序登录屏幕,他们在其中播放视频,并且您有登录或注册按钮。
图片 -
(点击图片放大)
【问题讨论】:
-
这个问题你解决了吗?
标签: android
我正在为我的 Android 应用制作登录屏幕,并且想知道如何使用视频作为背景而不是使用图像或简单的颜色?
我想让它类似于 Spotify / 圣经应用程序登录屏幕,他们在其中播放视频,并且您有登录或注册按钮。
图片 -
(点击图片放大)
【问题讨论】:
标签: android
您只需几个步骤即可将视频设置为应用的背景。
【讨论】:
首先新建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>
就是这样!
【讨论】:
NatureDevil 的回答和视频很棒,但是如果您单击一个按钮并打开一个新活动(例如唱歌)并决定单击设备上的后退箭头,则首先缺少两件事,主屏幕将显示黑屏,因为视频不会重启,所以你需要添加这个
@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"
【讨论】: