Mar*_*ues 20 android android-custom-view android-canvas mpandroidchart
点击自定义条形图(使用MPAndroidChart创建)后,我正在绘制工具提示.视图层次结构如下
<LinearLayout>
<TextView text=Move & Max Pain/>
<RelativeLayout with 2 textviews>
<chart
clipToChildren=false
clipToPadding=false
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
虽然View位于Chart或其中间兄弟中,但外观看起来很好.但是当它与它的兄弟碰撞时,工具提示被截断了

使用HierarchyViewer我可以看到内容存在,但它没有被绘制.
为了获得剪辑,我在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();
}
Run Code Online (Sandbox Code Playgroud)
如果我将Op更改为Region.Op.Replace,则工具提示会正确绘制,但它会替换工具栏内容,而不是在其下滚动.

您将需要您希望能够绘制工具提示的区域的边界,我假设这将是一个滚动视图。然后,您可以将工具提示边界与滚动条相交,以计算出应进行的剪切;以及是否应该绘制它。
用代码来解释它会是这样的(未经测试):
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1544 次 |
| 最近记录: |