[英]Android - Set a view to be on top of items drawn with canvas
我有一个Android应用程序,用户在照片上绘制,移动和重塑一些对象。 在此页面中,我的屏幕布局包括加载的照片和在其下方(纵向视图)的一些按钮。 我的视图看起来与我想要的xml如下:
<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>
问题是我希望按钮始终位于绘制对象的顶部。 现在,如果用户绘制一条线然后以一条边缘将低于图像的方式移动它,则该线将在按钮上方。 在那一点上它是不可触摸的,因为画布被设置为具有我的图像的位图,但它将是可见的。 如果线的一部分离开屏幕,我希望它以消失的方式消失。
我该如何实现呢? 是否有一些属性可以确保这些按钮始终位于绘制的对象上? 先感谢您!
如果你已经@Override
onDraw
或onLayout
方法,尽量使
<LinearLayout
android:id="@+id/buttons">
在前面使用v.bringToFront()
,其中v
将是您的LinearLayout。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.