问题
What can I do to fix the legend overlapping in androidplot?
Can I manipulate the legend placement?
回答1:
You can use this to enlarge the legend:
myPlot.getLegendWidget().setSize(new SizeMetrics(15, SizeLayoutType.ABSOLUTE, 200, SizeLayoutType.ABSOLUTE));
15 is the height and 200 the width.
Change the legend position:
myPlot.position(
myPlot.getLegendWidget(),
0,
XLayoutStyle.ABSOLUTE_FROM_RIGHT,
0,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.RIGHT_BOTTOM);
And reposition the domain label if you need to:
myPlot.position(myPlot.getDomainLabelWidget(),
0,
XLayoutStyle.ABSOLUTE_FROM_LEFT,
15,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.LEFT_BOTTOM);
回答2:
Some of the methods used in the above answer did not work for me. I guess things have changed in 4 years. Following code worked for me.
dynamicPlot.getLegendWidget().setSize(new Size(25, SizeLayoutType.ABSOLUTE, 400, SizeLayoutType.ABSOLUTE));
dynamicPlot.getLegendWidget().position(0,
XLayoutStyle.ABSOLUTE_FROM_RIGHT,
0,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.RIGHT_BOTTOM);
dynamicPlot.getDomainLabelWidget().position(0,
XLayoutStyle.ABSOLUTE_FROM_LEFT,
30,
YLayoutStyle.ABSOLUTE_FROM_BOTTOM,
AnchorPosition.LEFT_BOTTOM);`
change the layoutStyle and offsets as per your needs.
来源:https://stackoverflow.com/questions/10600178/androidplot-legend-overlapping