android - Prevent custom SurfaceView from drawing on top of other views -


i have created custom surfaceview use draw shapes, , user can zoom , pan view interact shapes. works great, problem shapes drawn on top of everything on screen, on top of other views such buttons , textviews. have tried ordering custom view , buttons in different ways in xml layout, tried parenting views framelayouts , relativelayouts (as suggested here).

i have buttons , other layout elements floating on top of custom view. seen in image below, when pan view rectangle obscure buttons.

how can prevent custom surfaceview drawing on top of everything?

enter image description here

my drawing code runs in separate thread in surfaceview class:

public class customshapeview extends surfaceview implements runnable, surfaceholder.callback {  /* other implementation stuff */  @override public void run() {     while (isdrawing) {         if (!holder.getsurface().isvalid())             continue; //wait till becomes valid            canvas canvas = null;         try {             canvas = holder.lockcanvas(null);             synchronized (holder) {                 try {                     lock.lock();                                                     canvas.concat(samplematrix);                     canvas.drawcolor(color.transparent, porterduff.mode.clear);                     drawshapes(canvas);                                      } {                     lock.unlock();                 }             }         } catch (exception e) {             e.printstacktrace();         } {             if (canvas != null) {                 holder.unlockcanvasandpost(canvas);             }         }            } } } 

my test xml layout, expect create button (left) behind custom view , button (right) floating above custom view, is:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">  <button     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="left"     android:id="@+id/button"     android:layout_alignparentbottom="true"     android:layout_alignparentleft="true"/>  <framelayout     android:layout_width="match_parent"     android:layout_height="match_parent">      <com.example.customshapeview         android:id="@+id/floor_plan_view"         android:layout_width="match_parent"         android:layout_height="match_parent"         /> </framelayout>  <relativelayout     android:layout_width="match_parent"     android:layout_height="match_parent">      <button         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="right"         android:id="@+id/button2"         android:layout_alignparentbottom="true"         android:layout_alignparentright="true"         android:layout_alignparentend="true"/> </relativelayout>    </relativelayout> 

in code calling function setzorderontop(true); made sure surface view drawn on top of everything. piece of code left in previous developer in order have custom background canvas instead of solid color. surfaceview tradeoff between having custom background canvas or being able draw views on top of canvas.

the options are

  1. with setzorderontop(true); there can custom backgrounds no overlaying views.
  2. with setzorderontop(false); there can overlaying views solid color backgrounds canvas (by calling e.g. canvas.drawcolor(color.white); clear between draw calls).

i chose second option value overlaying views on custom backgrounds.


Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -