How to android Z order?

Mico picture Mico · Sep 20, 2011 · Viewed 10.9k times · Source

In my app, I want to draw on top of the background image. I have the following xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg2"
>
    <com.myapp.drawings.DrawingSurface
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/drawingSurface"
    />
    <LinearLayout
            android:orientation="horizontal"
            android:background="@drawable/bg2" 
            android:layout_width="match_parent" 
            android:layout_height="match_parent">
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="OK"
                android:onClick="onClick"
                android:id="@+id/colorBlueBtn"
        />
        <Button
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="Save"
                android:onClick="onClick"
                android:id="@+id/saveBtn"
        />
    </LinearLayout>
</FrameLayout>

No, the problem is, my drawing is not showing when I try to draw on the drawing surface. The background image and buttons were shown. And once I saved it, the image file generated by my app is shown. I think the problem is the Z order of my layout.

Any ideas? Thanks for any help! :)

Answer

Dmitry Ryadnenko picture Dmitry Ryadnenko · Sep 20, 2011

Items that appear in xml first will be drawn first. So you surface view is beneath you linear layout.