How to order android Z?

In my application, I want to paint over a 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 that my drawing does not appear when I try to draw on the surface of the drawing. A background image and buttons were shown. And as soon as I saved it, the image file created by my application will be shown. I think the problem is in the order of my layout.

Any ideas? Thanks for any help! :)

+4
source share
2 answers

First, elements that appear in xml will be drawn. This way you see the surface below your linear layout.

+8
source

According to the description of Android developers FrameLayout

Child modes are drawn on the stack, with the last child added on top.

So, in your xml, LinearLayout last LinearLayout drawn, and since it has match_parent attributes, it completely hides your drawing surface.

So try using RelativeLayout and set the LinearLayout attributes LinearLayout only wrap_content , something like this:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 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="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true"> <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> </RelativeLayout> 

You can also completely exclude LinearLayout , and just set the button attributes so that they stay below, etc.

+5
source

All Articles