Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.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 视图外部边界未正确绘制_Android_Android Canvas_Android Custom View_Mpandroidchart - Fatal编程技术网

Android 视图外部边界未正确绘制

Android 视图外部边界未正确绘制,android,android-canvas,android-custom-view,mpandroidchart,Android,Android Canvas,Android Custom View,Mpandroidchart,在自定义条形图(使用MPAndroidChart创建)内单击后,我正在绘制工具提示。视图层次结构如下所示 <LinearLayout> <TextView text=Move & Max Pain/> <RelativeLayout with 2 textviews> <chart clipToChildren=false clipToPadding=false /> &l

在自定义条形图(使用MPAndroidChart创建)内单击后,我正在绘制工具提示。视图层次结构如下所示

<LinearLayout>
     <TextView text=Move & Max Pain/>
     <RelativeLayout with 2 textviews>
     <chart
       clipToChildren=false
       clipToPadding=false
     />
</LinearLayout>
如果将Op更改为Region.Op.Replace,则工具提示将正确绘制,但它将替换工具栏内容,而不是在工具栏下滚动


您需要能够绘制工具提示的区域边界,我假设这是一个滚动视图。然后,您可以将工具提示边界与滚动条相交,以确定剪切应该是什么;如果真的要画的话

要在代码中解释它,应该是这样的(未经测试):


你能发布这个的源代码吗?看起来很棒,我想好好看看。谢谢你,谢谢!但恐怕不行,对不起。我用于图表,但我自定义了一些部分(特别是X标签),这可能不是您唯一的问题,但我认为您误用了canvas.save()。你是不是应该在第一次翻译之前调用它,然后在翻译完成后调用restore,而不是在否定的方向上再次调用translate。它修复了棒棒糖上的问题,仍然无法处理Kitkat:(我在你的评论后更新了问题。谢谢!
    @Override
  public void draw(Canvas canvas, float posx, float posy) {
    // take offsets into consideration
    posx += getXOffset();
    posy += getYOffset();

    canvas.save();

    // translate to the correct position and draw
    canvas.translate(posx, posy);

    Rect clipBounds = canvas.getClipBounds();
    clipBounds.inset(0, -getHeight());
    canvas.clipRect(clipBounds, Region.Op.INTERSECT);

    draw(canvas);
    canvas.translate(-posx, -posy);

    canvas.restore();
  }
Rect scrollViewRect;  // the bounds of your scrollview
Rect tooltipRect;     // the bounds of your tooltip

bool intersects = tooltipRect.intersect(scrollViewRect)
if(intersects)
{
    canvas.clipRect(tooltipRect, Region.Op.REPLACE);
    draw(canvas);
}