Search code examples
androidandroidplot

AndroidPlot remains overlapping legend


Currently, I'm overlapping my plot and it shows as link https://www.dropbox.com/s/yaktr3ew2h4s6i6/Screenshot%202018-03-08%2011.26.52.jpg?dl=0

I have read most of the threads with solutions, but my legends still remain the same position. Following are the ways I have tried:

XYLegendWidget legendPlot = plot.getLegend();
legendPlot.position(150, HorizontalPositioning.ABSOLUTE_FROM_RIGHT, 10, VerticalPositioning.ABSOLUTE_FROM_BOTTOM);
plot.setLegend(legendPlot); //with or without remain the same as well
XYLegendWidget legendWidget2 = plot2.getLegend();
legendWidget2.position(100, HorizontalPositioning.ABSOLUTE_FROM_RIGHT, 0, VerticalPositioning.ABSOLUTE_FROM_BOTTOM);
plot2.setLegend(legendWidget2);


plot.getLegend().position(150, HorizontalPositioning.ABSOLUTE_FROM_RIGHT, 0, VerticalPositioning.ABSOLUTE_FROM_BOTTOM, Anchor.RIGHT_BOTTOM);
plot2.getLegend().position(100, HorizontalPositioning.ABSOLUTE_FROM_RIGHT, 0, VerticalPositioning.ABSOLUTE_FROM_BOTTOM, Anchor.RIGHT_BOTTOM);

I just want to position both legends side by side without overlapping.


Solution

  • With lots of the tryout. Finally, I managed to resolve my question. Following code is the solution which put into XML under your desired plot.

    ap:legendAnchor="right_bottom"
    ap:legendHorizontalPositioning="absolute_from_right"
    ap:legendHorizontalPosition="-10dp"
    ap:legendVerticalPositioning="relative_from_bottom"
    ap:legendVerticalPosition="0dp"
    

    Here's the image