How do I remove all space around a chart in AndroidPlot?

一笑奈何 提交于 2019-11-29 11:06:09
Nick

The Plot itself (mDynamicPlot in your example) is essentially a collection of widgets positioned in a shared space. The actual class that handles the positioning is LayoutManager.

In addition to positioning, the size of the Widget will also need to be adjusted to fill the entire Plot. Each Widget keeps track of its own size using an instance of SizeMetrics. You can modify the size of any Widget by invoking setSize(SizeMetrics newInstance); The "chart" area you are interested in corresponds to the XYGraphWidget. 

I have not personally tested this but I believe the code below should do what you want:

// get a handle to the XYGraphWidget:

Widget gw = mDynamicPlot.getGraphWidget();

// FILL mode with values of 0 means fill 100% of container:
SizeMetrics sm = new SizeMetrics(0,SizeLayoutType.FILL,
                                 0,SizeLayoutType.FILL));
gw.setSize(sm);

// get a handle to the layout manager:
LayoutManager lm = mDynamicPlot.getLayoutManager();

// position the upper left corner of gw in the upper left corner of the space 
// controlled by lm.
lm.position(gw, 0, XLayoutStyle.ABSOLUTE_FROM_LEFT,
            0, YLayoutStyle.ABSOLUTE_FROM_TOP);

SizeMetrics is no Longer used to set the size, instead Size is used with the same Constructor as SizeMetrics and the same way to use. new Call looks like this.

Widget gw = mPlot.getGraph();    
Size size = new Size(0,SizeMode.FILL,0,SizeMode.FILL);    
gw.setSize(size);
gw.position(0, HorizontalPositioning.ABSOLUTE_FROM_LEFT,0, VerticalPositioning.ABSOLUTE_FROM_TOP);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!