Android invalidate(rect)忽略边界

时间:2013-09-07 10:13:46

标签: android invalidation rect

当我在视图中调用invalidate(rect)时,我希望它清除画布上的“rect”区域,并执行onDraw中指定的操作。问题是,它忽略了给定的'rect'界限,并使整个视图无效。

我做了一个小测试程序来显示我的问题。启动应用程序时,将绘制第一行。当用户触摸屏幕时,绘制第二行(并在该区域上调用invalidate(rect))。第1行是故意不重绘的。 问题是第1行消失,屏幕上只显示第2行。

代码:

    public class TestInval extends View
    {

        ...    

        @Override
        protected void onDraw(Canvas canvas)
        {
            super.onDraw(canvas);

            Log.d(TAG, "onDraw bounds: " + canvas.getClipBounds()); //Logs: Rect(0, 0 - 720, 1134)

            if (drawOtherLine)
                canvas.drawLine(50, 50, 100, 100, defaultPaint);
            else
                canvas.drawLine(0, 0, 50, 50, defaultPaint);
        }

        ..
        public boolean onTouch(View view, MotionEvent motionEvent)
        {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP)
            {
                drawOtherLine = true;

                Rect invalidateRect = new Rect(50, 50, 100, 100);

                invalidate(invalidateRect);
            }

            return true;
        }


        @Override
        public void invalidate(Rect dirty)
        {
            Log.d(TAG, "invalidate: " + dirty); //Logs: Rect(50, 50 - 100, 100)
            super.invalidate(dirty);
        } 

expected actual

更新:

我的设备,运行4.1.2的三星Galaxy S3没有扎根,似乎是问题所在。在android模拟器上运行相同的测试应用程序会给出预期的剪切边界。仍然不确定为什么我的设备会出现这种情况。

0 个答案:

没有答案
相关问题