小智 33
您只需几个步骤即可将视频设置为应用的背景.
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应用程序.随意查看它,让我知道它是否有帮助:)首先制作新的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>
Run Code Online (Sandbox Code Playgroud)
然后在你的主布局中包含这个文件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>
Run Code Online (Sandbox Code Playgroud)
而已!
NatureDevil 的答案和视频很棒,但首先缺少两件事,如果您单击按钮并打开新的活动(例如注册)并决定单击设备上的后退箭头,主屏幕将出现黑屏,因为视频不会重新启动,所以你需要添加这个
@Override
protected void onResume() {
super.onResume();
// to restart the video after coming from other activity like Sing up
mVideoView.start();
}
Run Code Online (Sandbox Code Playgroud)
VideoView 从左向右全屏拉伸的其他内容添加:
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
27069 次 |
| 最近记录: |