2015-11-01 10 views
10

Androidアプリのログイン画面を作成していて、画像や簡単な色ではなく背景として動画を使用するにはどうすればいいですか?動画を背景に設定する

Spotify/Bibleアプリのログイン画面に似て、ビデオを再生し、サインインまたは登録するボタンがあります。

画像 -

(画像をクリックすると拡大します)

IMG:

IMG:

+0

この問題は解決しますか? – exequielc

答えて

4

まず新しい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> 

それだそれ!

+1

ビューページャは映像が左から右に全画面追加するストレッチしますので、VideoViewでは、いくつかのtransparend背景 –

+0

とレイアウトに追加する必要があるため、私は思う: アンドロイド:layout_alignParentEnd =「true」を アンドロイド:layout_alignParentStart = "真の" –

17

ビデオをアプリの背景として設定するには、いくつかの手順が必要です。

  1. ビデオビューを作成し、それが全体の領域を占めることを確認します。制約レイアウトを使用している場合は、ビデオビューのすべての制約を親に設定する必要があります。
  2. 私はどのように説明するビデオを作ってきたビデオ
     
    VideoView videoview = (VideoView) findViewById(R.id.videoview); 
    Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.test); 
    videoview.setVideoURI(uri); 
    videoview.start(); 
    
    を再生する「生」ディレクトリ
  3. にあなたのビデオファイルあなたの「RES」ディレクトリの下に
  4. 場所を「生」と呼ばれる新しいディレクトリを作成します。アンドロイドのJOOXログイン画面を作成して、Spotifyアプリのように見えるようにします。 :)それをチェックアウトし、それが助けなら、私に知らせて自由に感じる

https://youtu.be/tPeDn18FrGY

+1

これは動作しています、兄弟ありがとう! –

0

NatureDevilの答えとビデオは素晴らしいですが、あなたはボタンをクリックし、新しい活動を開くと2つのことのような最初に欠けています歌うアップし、デバイス上の戻る矢印をクリックすることを決定したビデオは、あなたがVideoViewは左からストレッチするため、この

@Override 
protected void onResume() { 
    super.onResume(); 
    // to restart the video after coming from other activity like Sing up 
    mVideoView.start(); 


} 

他の事を追加する必要はありそうに再起動しませんので、ホーム画面が黒い画面を与えます完全なフルスクリーンの追加:

android:layout_alignParentEnd="true" 
android:layout_alignParentStart="true" 
関連する問題