Android的 - 设置一个视图要上的项目上面用帆布画 [英] Android - Set a view to be on top of items drawn with canvas

查看:186
本文介绍了Android的 - 设置一个视图要上的项目上面用帆布画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,用户油漆,移动并通过照片重塑一些对象。在该页面中我的屏幕布局由加载的照片一些按钮和下方(纵向视图)。我的观点看起来完全一样,我希望它与下面的XML:

I have an android app where the user paints, moves and reshapes some objects over a photo. In this page my screen layout consists of the photo that is loaded and below it (in portrait view) some buttons. My view looks exactly as I want it 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 be always on top of the painted objects. Now if the user paints a line and then moves it in a way that one edge will go lower than the image, then this line will be over the buttons. It will be untouchable at that point because the canvas is set to the bitmap that has my image, but it will be visible. I would like it to disappear in the way it disappears if part of the line gets out of screen.

我如何能实现这一点?有一些属性,可确保这些按钮始终在画对象?谢谢你在前进!

How can I implement this? Is there some attribute that can ensure that these buttons are always over the painted objects? Thank you in advance!

推荐答案

如果您已经 @覆盖 的onDraw onLayout 方法,尽量使

If you've @Override onDraw or onLayout method, try bringing the

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

用在了前面 v.bringToFront(),其中 v 将是你的LinearLayout。

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

这篇关于Android的 - 设置一个视图要上的项目上面用帆布画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆