SurfaceView滚动型4.1下 [英] SurfaceView in ScrollView under 4.1

查看:388
本文介绍了SurfaceView滚动型4.1下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是问题所在。
出于性能的考虑,我选择使用SurfaceView绘制表格状,因为这东西是满的数据我使​​用的是滚动型作为SurfaceView父。

高兴地看到它的工作原理我个人的发展专用手机(HTC Desire HD的2.3.7)很好,我想测试它在我的公司开发专用的手机之一(谷歌Nexus S的4.1?),然后我个人的手机(HTC One X的4.1.1)。

出了错就这两个最后的,我SurfaceView刚满黑色经过一番〜80px滚动,转身回到它应该是什么样子,当我下这个〜80px滚动回(取决于屏幕大小)。

试图避免这种停电,我在一些测试模拟器...

从2.2(客户的愿望)到4.0.4,它工作得很好。

笑话是,在4.2 ...它的工作原理呢!

肯定地说,这是只有在4.1.x版的SurfaceView变黑!

下面是我SurfaceView code,我刚刚从样品复制,你可以找到的>。

 公共类MySurfaceView延伸SurfaceView
{
    公共MySurfaceView(上下文的背景下,ATTRS的AttributeSet)
    {
        超(背景下,ATTRS);
        //我用另一个SurfaceView后面画一个网格
        //这是滚动的独立与白色背景
        this.setZOrderOnTop(真);
        //此处同样理由
        。this.getHolder()和setFormat(PixelFormat.TRANSPARENT);
        。this.getHolder()的addCallback(本);
        this.getHolder()setSizeFromLayout()。
        //尝试没有这条线,并与软件和无太类型
        //和应用活动的硬件加速
        this.setLayerType(View.LAYER_TYPE_HARDWARE,NULL);
    }    @覆盖
    保护无效的onDraw(帆布油画)
    {
        super.onDraw(画布);        canvas.drawSomething()...
    }    公共无效surfaceCreated(SurfaceHolder持有人)
    {
        this.setWillNotDraw(假);        this.thread =新MySurfaceViewThread(this.getHolder(),这一点);
        this.thread.setRunning(真);
        this.thread.run();
    }    公共无效surfaceDestroyed(SurfaceHolder持有人)
    {
        this.thread.setRunning(假);
        布尔重试= TRUE;
        而(重试)
        {
            尝试
            {
                this.thread.join();
                重试= FALSE;
            }
            赶上(例外的例外)
            {
                Log.v(TAG,exception.getClass()的getName(),除外);
            }
        }
    }
}


这code片段可能是一个答案

 如果(VERSION.SDK_INT!= VERSION_ codeS.JELLY_BEAN)
{
    this.setZOrderOnTop(真);
}

但是,随着这样的问题是,背景得到黑色

我要吸取我就这一个背景SurfaceView绘制过这个特定Android版本的网格。

这并不是一个很好的解决方案,因为绘图网格在这个SurfaceView打破了滚动和双指缩放的平滑度。

Here is the problem. For performance reasons, I choose to use a SurfaceView to draw a table-like form, and because this stuff is full of data I use a ScrollView as SurfaceView parent.

Happy to see it works fine on my personal development-dedicated phone (HTC Desire HD 2.3.7), I tried to test it on one of my company development-dedicated phone (Google Nexus S 4.1.?) and then on my personal phone (HTC One X 4.1.1).

Something went wrong on those two last ones, my SurfaceView just turned black after some ~80px scroll and turned back to what it should look like when I scrolled back under this ~80px (depends on screen size).

Trying to avoid this blackout, I tested under some emulators...

From 2.2 (customer's wish) to 4.0.4, it works just great.

The joke is, under 4.2... it works too!

Definitely, that is only under 4.1.x that the SurfaceView turns black!

Here is my SurfaceView code, that I just copied from the sample you can find here.

public class MySurfaceView extends SurfaceView
{
    public MySurfaceView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        // I use another SurfaceView behind to draw a grid
        // that is scroll independent with a white background
        this.setZOrderOnTop(true);
        // Same reason here
        this.getHolder().setFormat(PixelFormat.TRANSPARENT);
        this.getHolder().addCallback(this);
        this.getHolder().setSizeFromLayout();
        // Tried without this line and with "software" and "none" types too
        // and hardware acceleration on application and activity
        this.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    }

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

        canvas.drawSomething()...
    }

    public void surfaceCreated(SurfaceHolder holder)
    {
        this.setWillNotDraw(false);

        this.thread = new MySurfaceViewThread(this.getHolder(), this);
        this.thread.setRunning(true);
        this.thread.run();
    }

    public void surfaceDestroyed(SurfaceHolder holder)
    {
        this.thread.setRunning(false);
        boolean retry = true;
        while(retry)
        {
            try
            {
                this.thread.join();
                retry = false;
            }
            catch(Exception exception)
            {
                Log.v(TAG, exception.getClass().getName(), exception);
            }
        }
    }
}

解决方案

This code snippet could be an answer

if(VERSION.SDK_INT != VERSION_CODES.JELLY_BEAN)
{
    this.setZOrderOnTop(true);
}

But the problem with doing this is that the background gets black.

I have to draw the grid I drawn in the "background" SurfaceView on this one too for this specific android version.

That is not a good solution, because drawing that grid in this SurfaceView breaks the smoothness of the scroll and the pinch-to-zoom.

这篇关于SurfaceView滚动型4.1下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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