TextView不会覆盖FrameLayout内部的VideoView

时间:2015-08-16 13:55:41

标签: android android-layout android-studio android-videoview

我想在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();
}

}

0 个答案:

没有答案