Video Splash不在屏幕中央 - Android Studio

时间:2017-07-03 15:17:21

标签: android video screen center splash

我在这里看到类似的东西,但我无法用给出的解决方案来解决。我试图在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>

1 个答案:

答案 0 :(得分:0)

尝试使用具有VideoView属性的相对布局替换LinearLayout android:layout_centerInParent =“true”

相关问题