Video Splash 不在屏幕上居中 - Android Studio



我在这里看到了类似的东西,但我无法用给出的解决方案来解决。我正在尝试在 Android Studio 项目中以初始屏幕的形式启动视频,它在开始时正确启动,但它不在屏幕中间居中,而是在顶部,我做错了什么?在项目本身不会出现任何错误,一切正常,只有视频没有集中。注意:我对Android Studio没有太多经验,所以如果代码中有一些无意义的东西,请纠正我。

安卓清单.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>

尝试将 LinearLayout 替换为具有 VideoView 属性的相对布局 android:layout_centerInParent="true">

相关内容

最新更新