两层,但不能显示在机器人底层两层、底层、机器人

由网友(空梦.)分享简介:我的工作类似刮奖的Andr​​oid项目。我在RelativeLayout的两层。底层包含一个ImageView的,和上层包含一个SurfaceView。问题是显示器一直是黑色,不表明即使我设置的ImageView canvas.drawColor(Color.TRANSPARENT)。我应该怎么做,如果我想从头开始...

我的工作类似刮奖的Andr​​oid项目。我在RelativeLayout的两层。底层包含一个ImageView的,和上层包含一个SurfaceView。

问题是显示器一直是黑色,不表明即使我设置的ImageView canvas.drawColor(Color.TRANSPARENT)

我应该怎么做,如果我想从头开始和擦除SurfaceView的一部分,露出下面的ImageView的?

在此先感谢。而我的英语不好对不起。

下面是我的布局:

 <?XML版本=1.0编码=UTF-8&GT?;< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android    机器人:方向=垂直    机器人:layout_width =FILL_PARENT    机器人:layout_height =FILL_PARENT    机器人:背景=@绘制/背景    机器人:填充=10dp    机器人:ID =@ + ID / layoutama    >    < RelativeLayout的        机器人:layout_width =FILL_PARENT        机器人:layout_height =WRAP_CONTENT    >        <的ImageButton            机器人:ID =@ + ID /复位            机器人:SRC =@绘制/ refresh_btn            机器人:背景=@空            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:layout_toRightOf =@ + ID /标志            机器人:paddingTop =10dp            机器人:paddingRight =8DP        />        <的ImageButton            机器人:ID =@ + ID /后退            机器人:SRC =@绘制/ back_btn            机器人:背景=@空            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT            机器人:layout_toRightOf =@ + ID /复位            机器人:paddingTop =10dp        />        < ImageView的            机器人:ID =@ + ID /标志            机器人:SRC =@绘制/图标            机器人:layout_width =WRAP_CONTENT            机器人:layout_height =WRAP_CONTENT        />    < / RelativeLayout的>    < AbsoluteLayout        机器人:ID =@ + ID / absolayo        机器人:layout_width =FILL_PARENT        机器人:layout_height =FILL_PARENT    >        < RelativeLayout的            机器人:ID =@ + ID / relatlayo            机器人:layout_width =FILL_PARENT            机器人:layout_height =FILL_PARENT        >            < ImageView的                机器人:layout_width =FILL_PARENT                机器人:layout_height =FILL_PARENT                机器人:SRC =@绘制/ image1的                机器人:scaleType =fitXY            />            < coba.ngegosok.MainGambar                机器人:ID =@ + ID / LayoDalam                机器人:layout_width =FILL_PARENT                机器人:layout_height =FILL_PARENT            />        < / RelativeLayout的>    < / AbsoluteLayout>< / LinearLayout中> 

这里的SurfaceView code:

 保护无效的onDraw(帆布油画){        //填充用黑色帆布        canvas.drawColor(Color.TRANSPARENT);        canvas.drawBitmap(eraseableBitmap,0,0,mBitmapPaint);        canvas.drawPath(的mpath页);    }    @覆盖    保护无效onSizeChanged(INT W,INT小时,INT oldw,诠释oldh){        super.onSizeChanged(W,H,oldw,oldh);        TW = W;        第= H;        mBitmap = Bitmap.createBitmap(W,H,Bitmap.Config.ARGB_8888);        mCanvas =新的Canvas(mBitmap);    }    私人无效touch_start(浮法X,浮法Y){        MX = X;        我= Y;        mPath.reset();        mPath.moveTo(X,Y);    }    私人无效TOUCH_MOVE(浮法X,浮法Y){        浮DX = Math.abs(X  -  MX);        浮DY = Math.abs(Y  - 我的);        如果(DX> = || TOUCH_TOLERANCE DY> = TOUCH_TOLERANCE){            //mPath.quadTo(mX,我的,(X + MX)/ 2,(Y + MY)/ 2);            MX = X;            我= Y;        }    }    私人无效touch_up(){        mPath.lineTo(MX,我的);        mCanvas.drawPath(的mpath页);        //杀死这个,所以我们不要双击平局        mPath.reset();    }    @覆盖    公共布尔onTouchEvent(MotionEvent事件){        static_x = event.getX();        static_y = event.getY();        如果(event.getAction()== MotionEvent.ACTION_DOWN){            touch_start(static_x,static_y);        }如果(event.getAction()== MotionEvent.ACTION_MOVE){                TOUCH_MOVE(static_x,static_y);        }如果(event.getAction()== MotionEvent.ACTION_UP){                润色();            }        返回true;    } 
从显示器到机器人 外企在中国建高科技工厂

解决方案

您不应该有SurfaceView后面的ImageView的,因为SurfaceView是不是绘制像普通视图绘制。表面为Z排序,以便它是窗口保持其SurfaceView后面;该SurfaceView冲头在其窗口的孔,以允许要被显示在其表面

在你的情况我会放置的ImageView在SurfaceView前,使用setVisibility(View.VISIBLE);当你想证明这一点。

另外,您可以使用myImageView.bringToFront();得到它的SurfaceView的顶部对齐。

I am working on an Android project similar to a scratch card. I have two layers in RelativeLayout. Bottom layer contains an ImageView, and top layer contains a SurfaceView.

The problem is the display stays black and doesn't show the ImageView even if I set canvas.drawColor(Color.TRANSPARENT).

What should I do if I want to scratch and erase the part of SurfaceView and reveal the ImageView below?

Thanks in advance. And I am sorry for the bad English.

Here's my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:padding="10dp"
    android:id="@+id/layoutama"
    >
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    >
        <ImageButton
            android:id="@+id/reset"
            android:src="@drawable/refresh_btn"
            android:background="@null"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/logo"
            android:paddingTop="10dp"
            android:paddingRight="8dp"
        />

        <ImageButton
            android:id="@+id/back"
            android:src="@drawable/back_btn"
            android:background="@null"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/reset"
            android:paddingTop="10dp"
        />

        <ImageView
            android:id="@+id/logo"
            android:src="@drawable/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        />

    </RelativeLayout>

    <AbsoluteLayout
        android:id="@+id/absolayo"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
    >
        <RelativeLayout
            android:id="@+id/relatlayo"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
        >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:src="@drawable/image1"
                android:scaleType="fitXY"
            />

            <coba.ngegosok.MainGambar
                android:id="@+id/LayoDalam"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
            />

        </RelativeLayout>
    </AbsoluteLayout>
</LinearLayout>

Here's the SurfaceView code:

        protected void onDraw(Canvas canvas) {
        // fills the canvas with black
        canvas.drawColor(Color.TRANSPARENT);

        canvas.drawBitmap(eraseableBitmap, 0, 0, mBitmapPaint);
        canvas.drawPath(mPath, p);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        tw = w;
        th = h;
        mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
        mCanvas = new Canvas(mBitmap);
    }

    private void touch_start(float x, float y) {
        mX = x;
        mY = y;
        mPath.reset();
        mPath.moveTo(x, y);
    }

    private void touch_move(float x, float y) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
            //mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
            mX = x;
            mY = y;
        }
    }

    private void touch_up() {
        mPath.lineTo(mX, mY);
        mCanvas.drawPath(mPath, p);
        // kill this so we don't double draw
        mPath.reset();
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        static_x = event.getX();
        static_y = event.getY();

        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            touch_start(static_x, static_y);
        } if (event.getAction() == MotionEvent.ACTION_MOVE) {
                touch_move(static_x, static_y);
        } if (event.getAction() == MotionEvent.ACTION_UP) {
                touch_up(); 
            }
        return true;
    }

解决方案

You should not have the imageView behind the SurfaceView, since the SurfaceView is not drawn like regular Views are drawn. The surface is Z ordered so that it is behind the window holding its SurfaceView; the SurfaceView punches a hole in its window to allow its surface to be displayed.

In your case I would place the ImageView in front of the SurfaceView and use setVisibility(View.VISIBLE); when you want to show it.

Alternatively you can use myImageView.bringToFront(); to get it aligned on top of the SurfaceView.

阅读全文

相关推荐

最新文章