android - TextView Does Not Overlay VideoView Inside of FrameLayout -
i trying have textview
displayed on top (overlay) of videoview
, , not happening. have 2 elements inside of framelayout
textview positions below videoview. understanding, supposed place on top.
i have tried various ways of adding textview programmatically , removing additional features of videoview e.g. ontouchlistener().
does have suggestions on how fix problem or explanation of overlaying views me problem? appreciated. have posted code below:
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: display picture here 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 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(); }
}
you creating new videoview instead of using 1 in xml layout , calling setcontentview replaces xml layout loaded first new videoview. that's why failing. not call setcontentview twice , change code below
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 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; } }); }
Comments
Post a Comment