我是 Android 和 AChartengine 的新手,我正在做我的项目。
假设我有这样的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<LinearLayout
android:id="@+id/displayECG"
android:layout_width="fill_parent"
android:layout_height="100px"
android:orientation="horizontal" >
</LinearLayout>
在 MainActivity.java 中,我的代码如下:
view = ChartFactory.getLineChartView(this, dataSet, renderer);
LinearLayout layout = (LinearLayout) findViewById(R.id.displayECG);
layout.addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
但是当我运行我的应用程序并得到一个图形时,它比布局空间小得多。我想要一个图表,它适合我的布局,那么我该怎么做呢?
谢谢,
最佳答案
您的图表实际上填满了整个布局,但默认情况下 AChartEngine 有很多附加功能已打开。我建议在创建图表之前添加以下几行:
renderer.setLegendHeight(1);
renderer.setZoomButtonsVisible(false);
renderer.setMargins(new int[] {0, 0, 0, 0});
您可能还需要其他一些东西,但这至少应该让您入门。此外,您的 displayECG
只有 100 像素高。这也可能是有限的。
关于android - 如何使图表适合android上的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23408748/