我如何删除AndroidPlot图表周围的所有空间? [英] How do I remove all space around a chart in AndroidPlot?

查看:358
本文介绍了我如何删除AndroidPlot图表周围的所有空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了在应用中使用androidPlot简约的图表,并一直试图删除多余的视觉元素。我已经把一切都做了,但我不能摆脱视图中的图表自身周围的一些空白空间。下面是它看起来像标记打开,只是坐在一个活动的根视图:

I've got a minimalist chart using androidPlot in an application, and have been trying to remove extraneous visual elements. I've got everything done, except that I cannot get rid of some empty spaces around the chart itself within the view. Here's what it looks like with markup turned on, just sitting in the root view of an Activity:

我怎样才能消除内部图表边界和外部视图边界之间的黑色空间?这里是我的code:

How can I eliminate the black space between the inner chart boundaries and the outer view boundary? Here's my code:

    mDynamicPlot = (XYPlot) findViewById(R.id.dynamicPlot);
    mDynamicPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0"));
    mDynamicPlot.addSeries(mCpuData, new LineAndPointFormatter(Color.rgb(51, 204, 255), null, Color.rgb(8, 153, 194)));
    mDynamicPlot.setDomainStepMode(XYStepMode.INCREMENT_BY_VAL);
    mDynamicPlot.setRangeBoundaries(0, 100, BoundaryMode.FIXED);
    mDynamicPlot.setDomainStepValue(10);
    mDynamicPlot.setRangeStepValue(5.0d);
    mDynamicPlot.setRangeValueFormat(new DecimalFormat("#"));

    mDynamicPlot.setTicksPerDomainLabel(Integer.MAX_VALUE);
    mDynamicPlot.getLayoutManager().remove(mDynamicPlot.getLegendWidget());
    mDynamicPlot.getLayoutManager().remove(mDynamicPlot.getRangeLabelWidget());
    mDynamicPlot.getLayoutManager().remove(mDynamicPlot.getDomainLabelWidget());
    mDynamicPlot.getLayoutManager().remove(mDynamicPlot.getTitleWidget());

    mDynamicPlot.getGraphWidget().setMarginTop(10);        

    mDynamicPlot.setBackgroundPaint(null);
    mDynamicPlot.getGraphWidget().setBackgroundPaint(null);
    mDynamicPlot.getGraphWidget().setGridBackgroundPaint(null);

    mDynamicPlot.getGraphWidget().setDomainLabelPaint(null);
    mDynamicPlot.getGraphWidget().setDomainOriginLabelPaint(null);

    mDynamicPlot.getGraphWidget().setGridLinePaint(null);
    mDynamicPlot.getGraphWidget().setDomainOriginLinePaint(null);
    mDynamicPlot.getGraphWidget().setRangeOriginLinePaint(null);

    mDynamicPlot.setDrawBorderEnabled(false);

和我的XML。右页边距是抵消我想摆脱的剩余空间:

And my XML. The right margin is to offset the left space which I want to get rid of:

<com.androidplot.xy.XYPlot
    android:id="@+id/dynamicPlot"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_marginTop="16dp"
    android:layout_marginRight="10dp"
    title="Dynamic Plot" />

我没有在XML做似乎影响内部边界,包括改变封闭的布局重心。我也尝试了这些,没有效果:

Nothing I do in XML seems to affect the inner bounds, including changing the enclosing layout gravity. I have also tried these, to no effect:

    mDynamicPlot.getRangeLabelWidget().setHeight(0);
    mDynamicPlot.getRangeLabelWidget().setPadding(0, 0, 0, 0);
    mDynamicPlot.getRangeLabelWidget().setMargins(0, 0, 0, 0);

    mDynamicPlot.getLegendWidget().setSize(new SizeMetrics(0, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.ABSOLUTE));
    mDynamicPlot.getRangeLabelWidget().setSize(new SizeMetrics(0, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.ABSOLUTE));
    mDynamicPlot.getDomainLabelWidget().setSize(new SizeMetrics(0, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.ABSOLUTE));

什么我需要做的摆脱所有的黑色空间?

What do I need to do to get rid of all that black space?

推荐答案

这是自该图(mDynamicPlot在你的例子)本质上是定位在一个共​​享空间小部件的集合。处理定位的实际类的LayoutManager。

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

在除定位,控件的尺寸也需要进行调整,以填充整个绘图。每个插件使用SizeMetrics的实例保留它自己的大小轨道。您可以通过调用的setSize(SizeMetrics的newInstance)修改任何控件的大小; 图表区域,你有兴趣对应于XYGraphWidget。

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 it's 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.

我没有亲自测试过这一点,但我相信,code以下应该做你想要什么:

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

//获得一个句柄XYGraphWidget:

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

这篇关于我如何删除AndroidPlot图表周围的所有空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆