0
我想写一个代码来绘制在android layout.C使用aChartengine绘制图形我成功地绘制了图形,但我面临的问题,以对齐图形在某个ViewGroup内的布局。如何在Android布局中正确对齐aChartEngine图表?
mycode的:
MainActivity.java
public class MainActivity extends ActionBarActivity {
List<double[]> xValues;
List<double[]> yValues;
List<double[]> yValues1;
GraphicalView view;
MultipleTemperatureChart multiple;
RelativeLayout rlt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xValues = new ArrayList<double[]>();
yValues = new ArrayList<double[]>();
yValues1 = new ArrayList<double[]>();
rlt = (RelativeLayout) findViewById(R.id.rlt);
multiple = new MultipleTemperatureChart(this);
int[] data = {143,144,145,137,156,146,158,139,144,143};
double[] doubTime = new double[data.length];
double[] doubNote = new double[data.length];
double[] doubZero = new double[data.length];
for(int i=0;i<data.length;i++){
doubTime[i] = index;
doubNote[i] = data[i];
doubZero[i] = 0;
index++;
}
xValues.add(doubTime);
yValues.add(doubNote);
yValues1.add(doubZero);
view = multiple.execute(getApplicationContext(),xValues,yValues,yValues1);
view.setBackgroundColor(Color.YELLOW);
view.setLayoutParams(new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 400));
rlt.addView(view);
}
}
activity_main.xml中
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp"
android:orientation="vertical"
android:background="#33cc00"
android:id="@+id/rltParams">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/rlt"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/rlt"
android:background="#cc4455"
android:id="@+id/view"/>
</RelativeLayout>
所以这些是我的问题的代码和屏幕截图。我想绘制绿色RelativeLayout以及红色视图内的图形需要低于图形布局。
请给我一些解决方案或技巧,以正确地在布局中绘制图形。
如果你想要把图表的绿色布局里面试试这个
谢谢,红视部件视图布局具有色码“#cc4455”,这是在颜色有红,对不起,我到现在也没解释它正确 – MyCode
没有,总布局红色,所以,视图布局覆盖整个屏幕 – MyCode