Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有硬件加速的'drawTextOnPath()'的奇怪行为_Android_Android Custom View_Hardware Acceleration - Fatal编程技术网

Android 带有硬件加速的'drawTextOnPath()'的奇怪行为

Android 带有硬件加速的'drawTextOnPath()'的奇怪行为,android,android-custom-view,hardware-acceleration,Android,Android Custom View,Hardware Acceleration,在硬件加速自定义视图添加到滚动视图或列表视图中,以下两个代码段产生相同的结果:(请忽略最佳实践一秒钟) @覆盖 受保护的void onDraw(画布){ super.onDraw(帆布); //定心材料 浮动中心X=getWidth()/2f; 浮动中心Y=getHeight()/2f; 浮子尺寸=80; 浮子半尺寸=尺寸/2f; 左浮动=中心X-半尺寸; 浮顶=中心-半尺寸; RectF oval=新的RectF(左、上、左+尺寸、上+尺寸); 路径路径=新路径(); 路径:addArc(椭圆

硬件加速自定义
视图
添加到
滚动视图
列表视图
中,以下两个代码段产生相同的结果:(请忽略最佳实践一秒钟)

@覆盖
受保护的void onDraw(画布){
super.onDraw(帆布);
//定心材料
浮动中心X=getWidth()/2f;
浮动中心Y=getHeight()/2f;
浮子尺寸=80;
浮子半尺寸=尺寸/2f;
左浮动=中心X-半尺寸;
浮顶=中心-半尺寸;
RectF oval=新的RectF(左、上、左+尺寸、上+尺寸);
路径路径=新路径();
路径:addArc(椭圆形,160359);
油漆=新油漆();
油漆.尺寸(30);
油漆.设置样式(样式.笔划);
drawTextOnPath(“Hello world”,path,0,0,paint);//
drawTextOnPath()
在Android 4.1之后受到硬件加速的支持 这里正式提到了这一点: 但下一条评论似乎在某种程度上表明了您的问题,因此可能是一个bug

当然,对于4.1之前的版本,不要使用硬件加速-通过调用
View.setLayerType(View.layer\u type\u software,null)
在视图上设置软件层类型,并尝试在性能与错误之间进行权衡

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas); 
    // centering stuff
    float centerX = getWidth() / 2f;
    float centerY = getHeight() / 2f;
    float size = 80;
    float halfSize = size / 2f;
    float left = centerX - halfSize;
    float top = centerY - halfSize;
    
    RectF oval = new RectF(left, top, left + size, top + size);
    
    Path path = new Path();
    path.addArc(oval, 160, 359);
    
    Paint paint = new Paint();
    paint.setTextSize(30);
    paint.setStyle(Style.STROKE);
    
    canvas.drawTextOnPath("Hello world", path, 0, 0, paint); //<--- line A
    canvas.drawCircle(centerX, centerY, 10, paint);          //<--- line B
}
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas); 
    // centering stuff
    float centerX = getWidth() / 2f;
    float centerY = getHeight() / 2f;
    float size = 80;
    float halfSize = size / 2f;
    float left = centerX - halfSize;
    float top = centerY - halfSize;
    
    RectF oval = new RectF(left, top, left + size, top + size);
    
    Path path = new Path();
    path.addArc(oval, 160, 359);
    
    Paint paint = new Paint();
    paint.setTextSize(30);
    paint.setStyle(Style.STROKE);
    
    canvas.drawCircle(centerX, centerY, 10, paint);          //<--- line B
    canvas.drawTextOnPath("Hello world", path, 0, 0, paint); //<--- line A
}