【问题标题】:Set a video as background将视频设置为背景
【发布时间】:2015-11-01 02:59:09
【问题描述】:

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

我想让它类似于 Spotify / 圣经应用程序登录屏幕,他们在其中播放视频,并且您有登录或注册按钮。

图片 -

(点击图片放大)

【问题讨论】:

  • 这个问题你解决了吗?

标签: android


【解决方案1】:

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

  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】:

    首先新建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"
    【解决方案3】:

    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"
    

    【讨论】:

      猜你喜欢
      • 2014-10-19
      • 2011-06-24
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 2012-03-25
      • 1970-01-01
      相关资源
      最近更新 更多