1

I would like to place a TextLabelWidget above a specific line in android Plot.

Is there any way to connect it directly to a line or to calculate the exact Y-position of an line.

Get the correct position of a point in AndroidPlot

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

That's my Code so far:

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

Picture:

enter image description here

Franz
  • 358
  • 6
  • 18

1 Answers1

1

If you just want to show a straight line with some text, you can use one of the subclasses of 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);

You can use the alternative constructors or marker.setTextPosition(...) to control exactly where the text appears.

Nick
  • 8,181
  • 4
  • 38
  • 63
  • Can I change the padding between line and text? – Franz May 11 '18 at 16:56
  • Not currently. It would be an easy thing to add though. Feel free to submit a feature request. You could also extend XYGraphWidget and override the drawMarkers method. – Nick May 11 '18 at 17:46
  • plot, gridRect and drawText are private can you change this or add getters for both? – Franz May 15 '18 at 11:47
  • @Franzi `XYGraphWidget.drawMarkerText(...)` is `protected` in the upcoming 1.5.5 release. That should make things a little simpler – Nick May 23 '18 at 15:52