
出于性能原因,我选择使用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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)