achartengine之折線圖---簡單用法(續)---圖形嵌套在頁面

今天剛好在看頁面佈局,想着怎麼把圖形也嵌套進來呢,嘗試了一下,弄了一個很簡單的頁面嵌套方法,以後有好的再補充。

如:

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


即可,效果圖如下:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章