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

本文介绍了一种在页面布局中嵌套图形的方法,并通过示例详细展示了如何使用RelativeLayout进行布局设计,同时提供了将折线图整合到现有布局的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

如:

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


即可,效果图如下:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值