Android Sets the view on top of elements drawn with the canvas.

I have an Android app where the user draws, moves and changes some objects on top of a photo. On this page, the screen layout consists of a loaded photo and below it (in portrait form) some buttons. My view looks the way I want with the xml below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linear" > <LinearLayout android:id="@+id/buttons" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" android:layout_alignParentBottom="true"> <ImageView android:id="@+id/draw" android:layout_width="80dp" android:layout_height="50dp" android:clickable="true" android:src="@drawable/draw"/> <ImageView android:id="@+id/delete" android:layout_width="80dp" android:layout_height="50dp" android:clickable="true" android:layout_toRightOf="@+id/erase" android:src="@drawable/delete"/> <ImageView android:id="@+id/done" android:layout_width="80dp" android:clickable="true" android:layout_height="50dp" android:layout_toRightOf="@+id/delete" android:src="@drawable/done"/> </LinearLayout> <ImageView android:id="@+id/photo" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_gravity="center" android:layout_above="@id/buttons"/> </RelativeLayout> 

The problem is that I want the buttons to always be on top of the painted objects. Now, if the user draws a line, and then moves it so that one edge falls below the image, then this line will be on the buttons. It will be inviolable at this point, because the canvas is set to a bitmap that has my image, but it will be visible. I would like it to disappear in the form in which it disappears if part of the line comes out of the screen.

How can i implement this? Is there any attribute that can guarantee that these buttons are always above colored objects? Thank you in advance!

+6
source share
1 answer

If you have the @Override onDraw or onLayout , try bringing

 <LinearLayout android:id="@+id/buttons"> 

in front using v.bringToFront() , where v will be your LinearLayout.

+8
source

Source: https://habr.com/ru/post/916843/


All Articles