Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 4.1中ScrollView中的SurfaceView大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是问题所在.
出于性能原因,我选择使用SurfaceView绘制类似于表格的表单,因为这些东西充满了数据,所以我使用ScrollView作为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代码,我刚刚从您可以找到的样本中复制了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);
            }
        }
    }
}

解决方法

这段代码可能是一个答案

if(VERSION.SDK_INT != VERSION_CODEs.jeLLY_BEAN)
{
    this.setZOrderOnTop(true);
}

但这样做的问题是背景变黑了.

我必须在这个特定的Android版本上绘制我在“背景”SurfaceView中绘制的网格.

这不是一个好的解决方案,因为在此SurfaceView中绘制网格会破坏滚动的平滑性和缩放到缩放.

大佬总结

以上是大佬教程为你收集整理的android – 4.1中ScrollView中的SurfaceView全部内容,希望文章能够帮你解决android – 4.1中ScrollView中的SurfaceView所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。