Android - 将视图设置在使用画布绘制的项目之上

2023-12-20

我有一个 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 or onLayout方法,尝试带

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

在前面使用v.bringToFront() where v将是您的 LinearLayout。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android - 将视图设置在使用画布绘制的项目之上 的相关文章

随机推荐