TextView 不覆盖 VideoView FrameLayout 内部

TextView Does Not Overlay VideoView Inside of FrameLayout

我试图让 TextView 显示在 VideoView 的顶部(叠加层),但没有成功。我在 FrameLayout 中有两个元素,TextView 位置在 VideoView 下方。据我了解,这应该放在最上面。

我尝试了多种方式来以编程方式添加 TextView 并删除 VideoView 的附加功能,例如onTouchListener()。

有没有人对如何解决这个问题有任何建议,或者对重叠视图的解释可以帮助我解决这个问题?任何帮助将不胜感激。我在下面发布了代码:

activity_splash.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.androidtitan.hotspots.Activity.SplashActivity">

<VideoView
    android:id="@+id/splashVideo"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<TextView android:id="@+id/splashTitle"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:layout_marginTop="25dp"
    android:text="placeholder text"
    android:textSize="60dp"
    android:textStyle="bold"
    android:textColor="@android:color/black"/>

SplashActivity.java

package com.androidtitan.hotspots.Activity;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.VideoView;

import com.androidtitan.hotspots.R;

public class SplashActivity extends Activity {
private static final String TAG = "hotspots";

TextView titleTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);

    titleTextView = (TextView) findViewById(R.id.splashTitle);

    try{
        splashScreen();

    } catch (Exception e) {
        //todo: we could display a picture here as an alternative
        Log.e(TAG, String.valueOf(e));
    }

    //this returns
    if(titleTextView.isShown()) {
        Log.e(TAG, "titleTextView.isShown()");
    }
    else {
        Log.e(TAG, "NOT SHOWN");
    }



}

@Override
public boolean onTouchEvent(MotionEvent ev) {
    return false;
}

public void splashScreen() {
    VideoView videoHolder = new VideoView(this);
    setContentView(videoHolder);
    Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
            + R.raw.splash);
    videoHolder.setVideoURI(video);
    videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            jumpMain(); //jump to the next Activity
        }
    });


    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    videoHolder.setLayoutParams(new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));

    videoHolder.start();

    videoHolder.setOnTouchListener(new View.OnTouchListener() {

        @Override
         public boolean onTouch(View v, MotionEvent event) {
            ((VideoView) v).stopPlayback();
            jumpMain();
            return true;
        }
    });
}

private synchronized void jumpMain() {
    Intent intent = new Intent(SplashActivity.this, ChampionActivity.class);
    startActivity(intent);
    finish();
}

}

您正在创建一个新的 VideoView,而不是在您的 XML 布局中使用它,并且还调用了 setContentView 来替换首先加载新 [=13] 的 XML 布局=].这就是它失败的原因。不要调用 setContentView 两次并更改您的代码如下

public void splashScreen() {
    VideoView videoHolder = (VideoView) findViewById(R.id.splashVideo);

    Uri video = Uri.parse("android.resource://" + getPackageName() + "/"
        + R.raw.splash);
    videoHolder.setVideoURI(video);
    videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            jumpMain(); //jump to the next Activity
        }
    });


    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    videoHolder.setLayoutParams(new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));

    videoHolder.start();

    videoHolder.setOnTouchListener(new View.OnTouchListener() {

        @Override
         public boolean onTouch(View v, MotionEvent event) {
            ((VideoView) v).stopPlayback();
            jumpMain();
        return true;
        }
    });
}