[英]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.