achartengine之折线图---简单用法(续)---图形嵌套在页面

来源:互联网 发布:sql 合计列最后一行 编辑:程序博客网 时间:2024/05/21 15:50

今天刚好在看页面布局,想着怎么把图形也嵌套进来呢,尝试了一下,弄了一个很简单的页面嵌套方法,以后有好的再补充。

如:

1.在布局文件中加入一个布局块:

<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"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" >    <!--  android:layout_above="将该控件的底部置于给定ID的控件之上" -->    <!--  android:layout_below="将该控件的底部置于给定ID的控件之下" -->    <!--  android:layout_toLeftOf="将该控件的右边缘和给定ID的控件的左边缘对齐" -->    <!--  android:layout_toRightOf="将该控件的左边缘和给定ID的控件的右边缘对齐" -->    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/hello_world"          android:id="@+id/textOne"         />    <EditText         android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:id="@+id/editOne"        android:layout_below="@id/textOne"        />          <Button           android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:id="@+id/ok"          android:layout_alignParentRight="true"          android:layout_below="@id/editOne"          />      <Button           android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:id="@+id/cancel"          android:layout_toLeftOf="@id/ok"          android:layout_below="@id/editOne"          /> <LinearLayout android:id="@+id/lineChar"      android:orientation="horizontal"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/ok"     />                        </RelativeLayout>


 

然后将昨天生成折线图的方法稍微做点修改:

由:

 GraphicalView  view = ChartFactory.getLineChartView(this, mDataset, mRenderer);        view.setBackgroundColor(Color.BLACK);        setContentView(view2);


变为:

 GraphicalView  view = ChartFactory.getLineChartView(this, mDataset, mRenderer);        view.setBackgroundColor(Color.BLACK);      LinearLayout view2 = (LinearLayout) findViewById(R.id.lineChar);       view2.addView(view);       // setContentView(view2);


即可,效果图如下: