Navigation Drawer and SurfaceView in fragment

Zbyszko

I want to use SurfeceView to make simple painting app like MS Paint. I created main activity with navigation drawer as toolbox for painting tools. I assumed that user I can operate on many surfaces (pages) so I made for each page separate fragment with SurfaceView inside.

In main activity I made customized button to open drawer. In fragment I set mSurfaceView.setZOrderOnTop(true) for SurfaveView and in SurfaceView mHolder.setFormat(PixelFormat.TRANSLUCENT)

Fragment layout:

<?xml version="1.0" encoding="utf-8"?>
<it.controls.PaintPageLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="20dp"
    android:background="#e0aa66cc"
    android:visibility="visible">
    <Button
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Sv"
        android:textSize="12sp"
        android:padding="0dp"
        android:background="#ffff4444"
        android:textColor="@android:color/black"
        android:minWidth="40dp"
        android:id="@+id/surface_fragment_debug_save" />
    <TextView
        android:id="@+id/surface_fragment_debug_info"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="end"
        android:text="debug_info"
        android:textColor="@android:color/white"
        android:background="@android:color/transparent"
        android:visibility="visible"
        android:layout_toEndOf="@+id/surface_fragment_debug_save" />
</RelativeLayout>
<it.controls.PaintSurfaceView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/surface_fragment_surface"
    />

Main layout is almost standard template generated from Android Studio, expect that my app is full screen (doesn't have Toolbar)

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
   <!-- The main content view -->
<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_coordinate_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    <!-- button to show left menu -->
    <android.support.v7.widget.AppCompatImageButton
        android:id="@+id/toolbox_toggle_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/toolbox_show_margin"
        android:layout_marginLeft="@dimen/toolbox_show_margin"
        android:contentDescription="@string/menu_show_hide_menu"
        android:src="@drawable/ic_menu_black_48dp"
        android:minWidth="@dimen/toolbox_show_button_size"
        android:minHeight="@dimen/toolbox_show_button_size"
        android:scaleType="fitCenter"
        android:background="@drawable/toolbox_new_page_button_border"
        />
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<FrameLayout
    android:id="@+id/menu_container"
    android:layout_width="@dimen/nav_drawer_width"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="horizontal"
    android:layout_gravity="start"
    tools:ignore="UselessParent">
</FrameLayout>
</android.support.v4.widget.DrawerLayout>

When I coded that I made simple drawing mechanism to draw path in SurfaceView and there is a problem.

My problem is that after I draw path I would like to change color so I must open toolbox (drawer). After I open drawer I saw that path is painted ON drawer as on screen below.

enter image description here

What I made wrong? How to hide SurfaceView behind drawer?

fadden

Your app has two distinct layers: the View UI layer, and the SurfaceView Surface layer. One of them is entirely on top of the other. You can't put one partially under the other. You put the SurfaceView Surface on top, so it's in front of all of your Views.

You might be better off with a custom View, rather than a SurfaceView. It'll mix in with your other Views, and for Canvas rendering it can be more efficient because it'll take advantage of hardware-accelerated rendering.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android: SurfaceView is blocking navigation drawer

From Dev

Navigation drawer default fragment

From Dev

Navigation drawer with tabs in fragment

From Dev

Navigation drawer with tabs in fragment

From Dev

Android Navigation Drawer Fragment

From Dev

Navigation drawer with diff fragment

From Dev

Introduce fragment in Navigation Drawer

From Dev

Navigation Drawer change fragment programmatically

From Dev

Communication between fragment in Navigation Drawer

From Dev

Save fragment state with navigation drawer

From Dev

Android Navigation Drawer Fragment State

From Dev

Fragment changes on rotation with navigation drawer

From Dev

Custom navigation drawer with activity & fragment

From Dev

Disabling navigation drawer from fragment

From Dev

Android Navigation Drawer Fragment State

From Dev

Changing fragment from Navigation drawer

From Dev

Custom navigation drawer with activity & fragment

From Dev

Refresh Navigation Drawer Fragment Android?

From Dev

Android Navigation Drawer Fragment Not Showing

From Dev

Communication between fragment in Navigation Drawer

From Dev

Android: Preference Fragment with a Navigation Drawer's Fragment

From Dev

Moving from fragment to fragment managed by Navigation Drawer

From Dev

Fragment UI's using navigation drawer

From Dev

Adding other elements (not ListView) to the navigation drawer with fragment

From Dev

Hamburger Icon does not show in Navigation Drawer Fragment

From Dev

Load Fragment before Navigation Drawer closes

From Dev

How to place two recyclerviews in a navigation drawer fragment

From Dev

How to open a new fragment from the navigation drawer?

From Dev

Change between fragment navigation drawer viewpagerindicator

Related Related

HotTag

Archive