简体   繁体   English

查看外部边界未正确绘制

[英]View outside bounds not drawing properly

I'm drawing a tooltip after clicking inside a custom bar chart (created with MPAndroidChart). 点击自定义条形图(使用MPAndroidChart创建)后,我正在绘制工具提示。 The view hierarchy is as follows 视图层次结构如下

<LinearLayout>
     <TextView text=Move & Max Pain/>
     <RelativeLayout with 2 textviews>
     <chart
       clipToChildren=false
       clipToPadding=false
     />
</LinearLayout>

While the View is inside the Chart or its inmediate sibling, everthing looks good. 虽然View位于Chart或其中间兄弟中,但外观看起来很好。 But the moment it collides with its sibling, the tooltip is truncated 但是当它与它的兄弟碰撞时,工具提示被截断了

在此输入图像描述

Using HierarchyViewer I can see that the content is present, but it's not drawn. 使用HierarchyViewer我可以看到内容存在,但它没有被绘制。

In order to get the clipping, I'm using this code inside draw 为了获得剪辑,我在draw中使用了这个代码

    @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();
  }

If I change Op to Region.Op.Replace, the tooltip is draw correctly but it replaces the Toolbar content, instead of scrolling under it. 如果我将Op更改为Region.Op.Replace,则工具提示会正确绘制,但它会替换工具栏内容,而不是在其下滚动。

在此输入图像描述

You'll need the bounds of the area in which you want to be able to draw the tooltip, and I'm assuming that would be a scrollview. 您将需要您希望能够绘制工具提示的区域的边界,我假设这将是一个scrollview。 Then you can intersect the tooltip bounds with the scroll to work out what the clipping should be; 然后,您可以将工具提示边界与滚动相交,以确定裁剪应该是什么; and if it should be drawn at all. 如果它应该被绘制。

To explain it in code it would be something like this (untested): 要在代码中解释它,它将是这样的(未经测试):

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM