将视频设置为背景

Nat*_*vil 25 android

我正在为我的Android应用程序制作登录屏幕,并想知道如何将视频用作背景而不是图像或简单的颜色?

我想使它类似于他们有视频播放的Spotify/Bible应用程序登录屏幕,并且您有登录或注册的按钮.

图片 -

(点击图片放大)

IMG:

IMG:

小智 33

您只需几个步骤即可将视频设置为应用的背景.

  1. 创建视频视图并确保它占据整个区域.如果使用约束布局,则需要将视频视图的所有约束设置为父级.
  2. 在"res"目录下创建一个名为"raw"的新目录
  3. 将您的视频文件放入"原始"目录
  4. 播放视频
    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应用程序.随意查看它,让我知道它是否有帮助:)

https://youtu.be/tPeDn18FrGY

  • 这正在工作,谢谢兄弟! (2认同)

Moh*_*med 8

首先制作新的XMLVideoView在其中添加:

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)

而已!


Rid*_*zag 5

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)