我正在使用 MPAndroidChart图书馆。
我在我的应用程序中实现了一个饼图。一切正常,但图表的顶部和末尾有一个空白区域。 我需要删除此空间以正确可视化我的 Activity 布局
我的问题是:
- 是否可以通过编程方式删除它们?
PD在我的布局中,没有 marginTop 或 marginBottom。
布局 xml:
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pieChart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/_home_consumed" >
</com.github.mikephil.charting.charts.PieChart>
最佳答案
您是否尝试过在 Chart
上调用 setOffsets(float left, float top, float right, float bottom)
?
// add data...
chart.setData(...);
// define new offsets
chart.setOffsets(0, 0, 0, 0);
// update transformation matrix
chart.getTransformer().prepareMatrixValuePx(chart);
chart.getTransformer().prepareMatrixOffset(chart);
chart.getContentRect().set(0, 0, chart.getWidth(), chart.getHeight());
// redraw
chart.invalidate();
这应该以编程方式消除所有偏移量。由于图表在调用 setData(...)
方法时自动调整其偏移量,为了保持偏移量,每次为图表设置新数据对象时都需要调用此方法。
我也知道这个很复杂,以后我会简化流程。
关于android - MPAndroidChart - 删除顶部和底部空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27945624/