android - Error when refreshing View on top of SurfaceView -



android - Error when refreshing View on top of SurfaceView -

i met problem when want display normal view object on top surfaceview. problem is: if set visibility of normal view invisible in layout xml file, refreshing of view not right - overlapped area of view , surface view cannot updated. if set visibility of normal view visible in layout xml, there no problem.

here test code:

package com.test; import java.io.ioexception; import android.app.activity; import android.media.mediaplayer; import android.media.mediaplayer.onpreparedlistener; import android.os.bundle; import android.os.handler; import android.os.message; import android.util.log; import android.view.surfaceholder; import android.view.surfaceholder.callback; import android.view.surfaceview; import android.view.view; import android.widget.linearlayout; public class testactivity extends activity implements callback, onpreparedlistener { private surfaceview msurface1; private surfaceholder msurfaceholder1; private mediaplayer mmediaplayer1; private linearlayout mlayout; /** called when activity first created. */ @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); mlayout = (linearlayout) findviewbyid(r.id.channel_subscribe); new handler() { @override public void handlemessage(message m) { if(mlayout.getvisibility() == view.invisible) mlayout.setvisibility(view.visible); else mlayout.setvisibility(view.invisible); this.sendemptymessagedelayed(0, 4000); } }.sendemptymessagedelayed(0, 4000); msurface1 = (surfaceview) findviewbyid(r.id.video_surface); msurfaceholder1 = msurface1.getholder(); msurfaceholder1.addcallback(this); msurfaceholder1.settype(surfaceholder.surface_type_push_buffers); mmediaplayer1 = new mediaplayer(); mmediaplayer1.setonpreparedlistener(this); seek { mmediaplayer1.setdatasource("/sdcard/d4.avi"); } grab (illegalargumentexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (illegalstateexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } } @override public void surfacechanged(surfaceholder arg0, int arg1, int arg2, int arg3) { // todo auto-generated method stub } @override public void surfacecreated(surfaceholder holder) { log.w("xxxxx", "surface1 created"); mmediaplayer1.setdisplay(holder); mmediaplayer1.prepareasync(); } @override public void surfacedestroyed(surfaceholder arg0) { // todo auto-generated method stub } @override public void onprepared(mediaplayer mp) { log.w("xxxxx", "mediaplayer prepared"); mp.start(); } }

and here layout file:

<?xml version="1.0" encoding="utf-8"?> <relativelayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <surfaceview android:id="@+id/video_surface" android:layout_width="480dip" android:layout_height="270dip" android:layout_marginleft="180dip" android:layout_margintop="40dip" /> <linearlayout android:id="@+id/channel_subscribe" android:visibility="invisible" android:orientation="vertical" android:background="#bb161616" android:layout_width="436.0sp" android:layout_height="148.0sp" android:layout_alignparentbottom="true"> <textview android:textsize="14.0dip" android:textstyle="normal" android:textcolor="#ffb7b7b7" android:id="@+id/subscribe_title" android:layout_width="wrap_content" android:layout_height="70.0sp" android:layout_marginleft="38.0sp" android:layout_margintop="18.0sp" android:layout_marginright="34.0sp" android:text="we hope enjoyed channel preview. subscribe channel, please press button below." /> <button android:id="@+id/subscribe_now_button" android:layout_width="184.0sp" android:layout_height="42.0sp" android:layout_marginleft="38.0sp" android:layout_marginright="34.0sp" android:layout_marginbottom="18.0sp" android:text="subscribenow" /> </linearlayout> </relativelayout>

problem solved.

the course of study is:

the subscribe dialog widget initialized invisible during inflating activity layout. and surfaceview used playing video attached activity window. when surfaceview invokes mparent.requesttransparentregion(this); in callback onattachedtowindow(), dialog widget invisible when viewroot calculate transparent region, overlapped area considered invisible, , painting of area incorrect.

to prepare issue, please phone call requesttransparentregion when alter visibility of widget if not visible when surfaceview attached window.

for example, can phone call mwidget.getparent().requesttransparentregion(msurfaceview).

since viewroot root parent of view hierachy, take same effect phone call surfaceview’s parent request transparentregion.

android layout refresh overlay surfaceview

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -