首页 > 解决方案 > AndroidPlot 获取直线的 Y 位置

问题描述

我想TextLabelWidget在 android Plot 中的特定行上方放置一个。

有没有办法将它直接连接到一条线或计算一条线的确切 Y 位置。

获取AndroidPlot中点的正确位置

https://stackoverflow.com/posts/comments/87452134?noredirect=1

到目前为止,这是我的代码:

TextLabelWidget txtText = new TextLabelWidget(
                    rdPuls.getLayoutManager(),
                    "Some Text",
                    null,  // TextLabelWidget instances "pack" to wrap the actual text size
                    TextOrientation.HORIZONTAL);
            txtText.getLabelPaint().setColor(getColor(R.color.biosign_green));
            txtText.getLabelPaint().setTextSize(PixelUtils.dpToPix(15));
            txtText.position(
                    // add a right margin of 4dp:
                    0, PixelUtils.dpToPix(80)

                    // center the text with the plot space vertically:
                    PixelUtils.dpToPix(80), VerticalPositioning.ABSOLUTE_FROM_BOTTOM,

                    // use the middle of the right edge of the text widget as the anchor:
                    Anchor.RIGHT_MIDDLE);

图片:

在此处输入图像描述

标签: androidpositionandroidplot

解决方案


如果您只想用一些文本显示一条直线,您可以使用以下子类之一XYValueMarker

YValueMarker marker = new YValueMarker(35, "someText");
plot.addMarker(marker);

// later, if you want to dynamically move it around: (dont forget 
// to call plot.redraw() if you do though)
marker.setValue(34);

您可以使用替代构造函数或marker.setTextPosition(...)精确控制文本出现的位置。


推荐阅读