2017-07-03 51 views
0

我在这里看到类似的东西,但我无法解决给出的解决方案。我试图在Android Studio项目中启动视频作为启动画面,它在正确的开始处启动,但它不在屏幕中央居中,位于顶部,我做错了什么?在该项目本身并没有出现任何错误,一切正常,只有视频不集中。注意:我没有太多的Android Studio经验,所以如果代码中没有任何意义,请纠正我。视频飞溅不在屏幕中心 - Android Studio

的AndroidManifest.xml:

... 

<!-- Activities --> 
     <activity 
      android:name="com.sherdle.universal.splash_demo" 
      android:theme="@style/AppThemeBar" 
      android:configChanges="orientation|screenSize" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name="com.sherdle.universal.MainActivity" /> 
     <activity android:name=".providers.yt.player.YouTubePlayerActivity" 
      android:configChanges="keyboardHidden|orientation|screenSize" 
      android:screenOrientation="sensor" 
      android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"/> 

... 

splash_demo.java:

... 

import android.app.Activity; 
import android.content.Intent; 
import android.media.MediaPlayer; 
import android.net.Uri; 
import android.os.Bundle; 
import android.widget.VideoView; 

/** 
* Created by rmm on 12/7/2016. 
*/ 

public class splash_demo extends Activity { 
    @Override 
    protected void onCreate(Bundle sa){ 
     super.onCreate(sa); 
     try{ 
      VideoView videoView = new VideoView(this); 
      setContentView(R.layout.activity_splash); 
      Uri path = Uri.parse("android.resource://"+getPackageName()+"/"+ +R.raw.vid1); 
videoView.setVideoURI(path); 

      videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener(){ 
       @Override 
       public void onCompletion(MediaPlayer mediaPlayer) { 
        jump(); 
       } 


      }); 
videoView.start(); 
     }catch (Exception e){ 
      jump(); 
     } 



    } 
    private void jump() { 

     if(isFinishing()) 
      return; 
     startActivity(new Intent(this,MainActivity.class)); 
     finish(); 
    } 
} 

activity_splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_splash" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    android:gravity="center" 
    android:background="#ffffff" 
    tools:context="com.sherdle.universal.splash_demo"> 


    <VideoView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/videoView" /> 
</LinearLayout> 

回答

0

尝试用相对布局与VideoView更换的LinearLayout属性的android:layout_centerInParent =”真“

+0

对不起,我没有什么经验,我添加了相对布局,但我不知道在哪里插入layout_centerInParent =“true”,你能告诉方法吗? – nauvaro

+0

@nauvaro

+0

我遵循的步骤,但是现在屏幕全黑,没有任何反应 – nauvaro