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>
對不起,我沒有什麼經驗,我添加了相對佈局,但我不知道在哪裏插入layout_centerInParent =「true」,你能告訴方法嗎? – nauvaro
@nauvaro –
我遵循的步驟,但是現在屏幕全黑,沒有任何反應 – nauvaro