Android开发中使用achartengine绘制各种图表的方法

本文实例讲述了Android开发中使用achartengine绘制各种图表的方法。分享给大家供大家参考,具体如下:

1. ABarChart.java

package com.anjoyo.achartengine;
import java.util.Random;
import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.model.CategorySeries;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.renderer.SimpleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class ABarChart {
  public Intent execute(Context context) {
    return ChartFactory.getBarChartIntent(context, getBarChartDataset(), getBarChartRenderer(), Type.DEFAULT);
  }
  private XYMultipleSeriesRenderer getBarChartRenderer() {
    // TODO Auto-generated method stub
    XYMultipleSeriesRenderer renderer=new XYMultipleSeriesRenderer();
    SimpleSeriesRenderer r;
    r=new SimpleSeriesRenderer();
    r.setColor(Color.BLUE);
    renderer.addSeriesRenderer(r);
    r=new SimpleSeriesRenderer();
    r.setColor(Color.GREEN);
    renderer.addSeriesRenderer(r);
    setBarChartRenderer(renderer);
    return renderer;
  }
  private void setBarChartRenderer(XYMultipleSeriesRenderer renderer) {
    // TODO Auto-generated method stub
    renderer.setChartTitle("Bar Chart");
    renderer.setXTitle("X Axis");
    renderer.setYTitle("Y Axis");
    renderer.setXAxisMax(10.5);
    renderer.setXAxisMin(0.5);
    renderer.setYAxisMax(210);
    renderer.setYAxisMin(0);
  }
  private XYMultipleSeriesDataset getBarChartDataset() {
    // TODO Auto-generated method stub
    XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
    final int SERIES_NR=2;
    final int NR=10;
    Random random=new Random();
    for (int i = 0; i < SERIES_NR; i++) {
      CategorySeries series=new CategorySeries("Bar Chart---"+(i+1));
      for (int j = 0; j < NR; j++) {
        series.add(100+random.nextInt(100));
      }
      dataset.addSeries(series.toXYSeries());
    }
    return dataset;
  }
}

2. ABubbleChart.java

package com.anjoyo.achartengine;
import java.util.Random;
import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYValueSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class ABubbleChart {
  private final int SERIES_NR = 3;
  private final int NR = 20;
  public Intent execute(Context context) {
    return ChartFactory.getBubbleChartIntent(context,
        getBubbleChartDataset(), getBubbleChartRenderer(),
        "Bubble Chart Demo");
  }
  private XYMultipleSeriesRenderer getBubbleChartRenderer() {
    // TODO Auto-generated method stub
    XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
    int[] linearColor = { Color.RED, Color.GREEN, Color.BLUE };
    XYSeriesRenderer r;
    for (int i = 0; i < SERIES_NR; i++) {
      // entry=new XYEntry<Integer, Integer>(key, value);
      r = new XYSeriesRenderer();
      r.setColor(linearColor[i]);
      r.setPointStyle(PointStyle.POINT);
      r.setLineWidth(2);
      renderer.addSeriesRenderer(r);
    }
    setBarChartRenderer(renderer);
    return renderer;
  }
  private XYMultipleSeriesDataset getBubbleChartDataset() {
    // TODO Auto-generated method stub
    XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
    for (int i = 0; i < SERIES_NR; i++) {
      XYValueSeries series = new XYValueSeries("Bubble Chart---"
          + (i + 1));
      int temp = 10 * i;
      int[][] data = getBasicData();
      for (int j = 0; j < data.length; j++) {
        if((j+1)%5 ==0){
          int x = data[j][0];
          int y = temp;
          int value=data[j][1]+temp;
          series.add(x, y, value);
        }
      }
      dataset.addSeries(series);
    }
    return dataset;
  }
  private int[][] getBasicData() {
    int[][] data = new int[20][2];
    Random rand = new Random();
    for (int i = 0; i < data.length; i++) {
      data[i][0] = i;
      data[i][1] = 20 + rand.nextInt(20) % 20;
    }
    return data;
  }
  private void setBarChartRenderer(XYMultipleSeriesRenderer renderer) {
    // TODO Auto-generated method stub
    renderer.setChartTitle("Bubble Chart");
    renderer.setXTitle("X Axis");
    renderer.setYTitle("Y Axis");
    renderer.setXAxisMax(20);
    renderer.setXAxisMin(0);
    renderer.setYAxisMax(30);
    renderer.setYAxisMin(0);
    renderer.setAntialiasing(true);//没有看出有啥效果来
    renderer.setApplyBackgroundColor(true);//设置背景颜色
    renderer.setBackgroundColor(Color.TRANSPARENT);
    renderer.setShowAxes(true);//
    renderer.setAxesColor(Color.GRAY);
    renderer.setClickEnabled(true);//设置了之后,不可再拖动
    renderer.setZoomButtonsVisible(true);//设置伸缩按钮是否可见
    renderer.setZoomEnabled(true);
    renderer.setExternalZoomEnabled(true);//设置是否可以向伸缩
    renderer.setLabelsColor(Color.GREEN);
    renderer.setLabelsTextSize(16);
  }
}

3. ALinearChart.java

package com.anjoyo.achartengine;
import java.util.Random;
import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class ALinearChart {
  private final int SERIES_NR=3;
  private final int NR=20;
  public Intent execute(Context context) {
    return ChartFactory.getLineChartIntent(context, getLinearChartDataset(), getLinearChartRenderer(), "Linear Chart Another");
  }
  private XYMultipleSeriesRenderer getLinearChartRenderer() {
    // TODO Auto-generated method stub
    int[] linearColor={Color.RED, Color.GREEN, Color.BLUE};
    int[] belowLinearColor={Color.YELLOW, Color.CYAN, Color.GRAY};
    XYMultipleSeriesRenderer renderer=new XYMultipleSeriesRenderer();
    XYSeriesRenderer tempRender;
    for (int i = 0; i < SERIES_NR; i++) {
      tempRender=new XYSeriesRenderer();
      tempRender.setColor(linearColor[i]);
//     tempRender.setFillBelowLine(true);
//     tempRender.setFillBelowLineColor(belowLinearColor[i]);
      tempRender.setPointStyle(PointStyle.POINT);
      tempRender.setLineWidth(2);
      renderer.addSeriesRenderer(tempRender);
    }
    setLinearChartRenderer(renderer);
    return renderer;
  }
  private void setLinearChartRenderer(XYMultipleSeriesRenderer renderer) {
    // TODO Auto-generated method stub
    renderer.setChartTitle("Three Linear Chart");
    renderer.setXAxisMax(20);
    renderer.setXAxisMin(0);
    renderer.setYAxisMax(60);
    renderer.setYAxisMin(0);
  }
  private XYMultipleSeriesDataset getLinearChartDataset() {
    // TODO Auto-generated method stub
    XYMultipleSeriesDataset dataset=new XYMultipleSeriesDataset();
    for (int i = 0; i < SERIES_NR; i++) {
      XYSeries series=new XYSeries("Stock Trend---"+(i+1));
      int temp=10*i;
      int[][] data=getBasicData();
      for (int j = 0; j < data.length; j++) {
        int x=data[j][0];
        int y=temp+data[j][1];
        series.add(x, y);
      }
      dataset.addSeries(series);
    }
    return dataset;
  }
  private int[][] getBasicData() {
    int[][] data=new int[20][2];
    Random rand=new Random();
    for (int i = 0; i < data.length; i++) {
      data[i][0]=i;
      data[i][1]=20+rand.nextInt(20)%20;
    }
    return data;
  }
}

4. APieChart.java

package com.anjoyo.achartengine;
import org.achartengine.ChartFactory;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class APieChart {
  private double[] values = { 25, 30, 45 };
  public APieChart() {
    // TODO Auto-generated constructor stub
  }
  public APieChart(double[] values) {
    if (values.length == 3) {
      for (int i = 0; i < values.length; i++) {
        this.values[i] = values[i];
      }
    }
  }
  public Intent execute(Context context) {
    int[] colors={Color.BLUE, Color.GREEN, Color.YELLOW};
    DefaultRenderer renderer=buildCategoryRenderer(colors);
    renderer.setAntialiasing(true);//没有看出有啥效果来
    renderer.setApplyBackgroundColor(true);//设置背景颜色
    renderer.setBackgroundColor(Color.TRANSPARENT);
    renderer.setShowAxes(true);//
    renderer.setAxesColor(Color.GRAY);
    renderer.setClickEnabled(true);//设置了之后,不可再拖动
    renderer.setZoomButtonsVisible(true);//设置伸缩按钮是否可见
    renderer.setZoomEnabled(true);
    renderer.setExternalZoomEnabled(true);//设置是否可以向伸缩
    renderer.setLabelsColor(Color.GREEN);
    renderer.setLabelsTextSize(16);
//   renderer.setLegendHeight(50);
//   renderer.setPanEnabled(true);
    renderer.setStartAngle(180);//好像不好用啊
    CategorySeries series=new CategorySeries("Fruit Ratio");
    series.add("Apple", values[0]);
    series.add("Banana", values[1]);
    series.add("Orange", values[2]);
    return ChartFactory.getPieChartIntent(context, series, renderer, "水果");
  }
  private DefaultRenderer buildCategoryRenderer(int[] colors) {
    DefaultRenderer renderer=new DefaultRenderer();
    renderer.setApplyBackgroundColor(true);
    renderer.setBackgroundColor(Color.GRAY);
    renderer.setLabelsTextSize(20);
    renderer.setChartTitle("饼状图");
    renderer.setChartTitleTextSize(20);
    renderer.setLegendTextSize(20);
    renderer.setLegendHeight(50);
    for (int i = 0; i < colors.length; i++) {
      int j = colors[i];
      SimpleSeriesRenderer r=new SimpleSeriesRenderer();
      r.setColor(j);
      renderer.addSeriesRenderer(r);
    }
    return renderer;
  }
}

5. MainActivity.java

package com.anjoyo.achartengine;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity {
  private Button lineChartBtn;
  private Button areaChartBtn;
  private Button scatterChartBtn;
  private Button timeChartBtn;
  private Button barChartBtn;
  private Button pieChartBtn;
  private Button bubbleChartBtn;
  private Button doughnutChartBtn;
  private Button rangeBarChartBtn;
  private Button dialChartBtn;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lineChartBtn=(Button) findViewById(R.id.line_chart);
    areaChartBtn=(Button) findViewById(R.id.area_chart);
    scatterChartBtn=(Button) findViewById(R.id.scatter_chart);
    timeChartBtn=(Button) findViewById(R.id.time_chart);
    barChartBtn=(Button) findViewById(R.id.bar_chart);
    pieChartBtn=(Button) findViewById(R.id.pie_chart);
    bubbleChartBtn=(Button) findViewById(R.id.bubble_chart);
    doughnutChartBtn=(Button) findViewById(R.id.doughnut_chart);
    rangeBarChartBtn=(Button) findViewById(R.id.range_bar_chart);
    dialChartBtn=(Button) findViewById(R.id.dial_chart);
    OnClickListener listener=new AChartEngineListener();
    lineChartBtn.setOnClickListener(listener);
    pieChartBtn.setOnClickListener(listener);
    barChartBtn.setOnClickListener(listener);
    bubbleChartBtn.setOnClickListener(listener);
  }
  class AChartEngineListener implements OnClickListener{
    @Override
    public void onClick(View v) {
      // TODO Auto-generated method stub
      switch (v.getId()) {
      case R.id.line_chart:
//       Intent intent=new Intent(MainActivity.this, LinearChartActivity.class);
//       startActivity(intent);
        Intent linearChartIntent=new ALinearChart().execute(MainActivity.this);
        startActivity(linearChartIntent);
        break;
      case R.id.area_chart:
        break;
      case R.id.scatter_chart:
        break;
      case R.id.time_chart:
        break;
      case R.id.bar_chart:
        Intent barChartIntent=new ABarChart().execute(MainActivity.this);
        startActivity(barChartIntent);
        break;
      case R.id.pie_chart:
        Intent pieChartIntent=new APieChart().execute(MainActivity.this);
        startActivity(pieChartIntent);
        break;
      case R.id.bubble_chart:
        Intent bubbleChartIntent=new ABubbleChart().execute(MainActivity.this);
        startActivity(bubbleChartIntent);
        break;
      case R.id.doughnut_chart:
        break;
      case R.id.range_bar_chart:
        break;
      case R.id.dial_chart:
        break;
      default:
        break;
      }
    }
  }
}

6. LinearChartActivity.java

package com.anjoyo.achartengine;
import java.util.Random;
import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
public class LinearChartActivity extends Activity {
  private XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
  private XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
  private XYSeries currentSeries;
  private XYSeriesRenderer currentRenderer;
  private String dateFormat;
  private GraphicalView chartView;
  @Override
  protected void onRestoreInstanceState(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onRestoreInstanceState(savedInstanceState);
    dataset = (XYMultipleSeriesDataset) savedInstanceState
        .getSerializable("dataset");
    renderer = (XYMultipleSeriesRenderer) savedInstanceState
        .getSerializable("renderer");
    currentSeries = (XYSeries) savedInstanceState
        .getSerializable("current_series");
    currentRenderer = (XYSeriesRenderer) savedInstanceState
        .getSerializable("current_renderer");
    dateFormat = savedInstanceState.getString("date_format");
  }
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    // TODO Auto-generated method stub
    super.onSaveInstanceState(outState);
    outState.putSerializable("dataset", dataset);
    outState.putSerializable("renderer", renderer);
    outState.putSerializable("current_series", currentSeries);
    outState.putSerializable("current_renderer", currentRenderer);
    outState.putString("date_format", dateFormat);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.stock_chart);
    String seriesTitle = "上证指数";
    XYSeries series = new XYSeries(seriesTitle);
    dataset.addSeries(series);
    currentSeries = series;
    XYSeriesRenderer seriesRenderer = new XYSeriesRenderer();
    seriesRenderer.setColor(Color.BLUE);
    seriesRenderer.setFillBelowLine(true);
//   seriesRenderer.setFillBelowLineColor(Color.RED);//折线下面区域是否添加颜色
    seriesRenderer.setPointStyle(PointStyle.POINT);
    seriesRenderer.setLineWidth(3);
    renderer.addSeriesRenderer(seriesRenderer);
//   添加另外一条曲线图
//   seriesRenderer = new XYSeriesRenderer();
//   seriesRenderer.setColor(Color.GREEN);
//   seriesRenderer.setFillBelowLine(true);
//   seriesRenderer.setFillBelowLineColor(Color.YELLOW);
//   seriesRenderer.setPointStyle(PointStyle.POINT);
//   seriesRenderer.setLineWidth(3);
//   renderer.addSeriesRenderer(seriesRenderer);
    renderer.setYAxisMin(0);
    renderer.setYAxisMax(100);
    renderer.setXAxisMax(20);
    renderer.setShowGrid(false);
    renderer.setXLabels(20);
    renderer.setChartTitle("上证指数-24小时趋势图");
    currentRenderer = seriesRenderer;
    double x = 0;
    double y = 0;
    int[][] xyValues = getValues();
//   for (int i = 0; i < 2; i++) {
//
      for (int j = 0; j < xyValues.length; j++) {
        x=xyValues[j][0];
        y=xyValues[j][1];
        currentSeries.add(x, y);
      }
//   }
  }
  @Override
  protected void onResume() {
    // TODO Auto-generated method stub
    if(chartView == null){
      LinearLayout layout=(LinearLayout) findViewById(R.id.chart);
      chartView=ChartFactory.getLineChartView(this, dataset, renderer);
      layout.addView(chartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    }else {
      chartView.setBackgroundResource(R.id.chart);
      chartView.repaint();
    }
    super.onResume();
  }
  private int[][] getValues() {
    // TODO Auto-generated method stub
    int[][] xyValues = new int[20][2];
    Random rand=new Random();
    for (int i = 0; i < xyValues.length; i++) {
      xyValues[i][0]=i;
      xyValues[i][1]=rand.nextInt(100);
    }
    return xyValues;
  }
}

7. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.anjoyo.achartengine"
  android:versionCode="1"
  android:versionName="1.0" >
  <uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />
  <application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppBaseTheme"
     >
    <activity
      android:name="com.anjoyo.achartengine.MainActivity"
      android:label="@string/app_name" >
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:name=".LinearChartActivity"></activity>
    <activity android:name="org.achartengine.GraphicalActivity"></activity>
  </application>
</manifest>

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。

(0)

相关推荐

  • Android中使用achartengine生成图表的具体方法

    今天在做项目的时候用到了图表功能,记录下来 achartengine是google的一个开源项目,可以在https://code.google.com/p/achartengine/ 下载技术文档,jar包以及项目源代码 demo下载:https://code.google.com/p/achartengine/downloads/list 一.饼状图 新建工程,添加achartengine  jar包 PieChart.java 复制代码 代码如下: package com.meritit.f

  • 解决Android SurfaceView绘制触摸轨迹闪烁问题的方法

    本文分享了解决SurfaceView触摸轨迹闪烁问题的方法,供大家参考,具体内容如下 第一种解决SurfaceView触摸轨迹闪烁问题的方法: 由于SurfaceView使用双缓存机制,两张画布轮流显示到屏幕上.那么,要存储触摸轨迹并避免两张画布内容不一致造成的闪烁问题,完全可以利用保存绘制过程并不断重新绘制的方法解决闪烁,而且这样还顺带解决了多次试验中偶尔出现的因为moveTo()函数不能读取到参数执行默认设置(参数设为上次的触摸点)而出现的断线连接闪烁问题,详细代码如下: package c

  • Android中使用ListView绘制自定义表格技巧分享

    先上一下可以实现的效果图  要实现的效果有几方面 1.列不固定:可以根据数据源的不同生成不同的列数 2.表格内容可以根据数据源的定义合并列 3.要填写的单元格可以选择自定义键盘还是系统键盘 奔着这三点,做了个简单的实现,把源码贴一下(因为该点是主界面中的一部分,不便于放整个Demo) 自定义适配器,CallBackInterface是自定义的回调接口,这里定义回调是因为数据输入时需要及时保存 复制代码 代码如下: public class SiteDetailViewAdapter extend

  • Android listView 绘制表格实例详解

    Android  listView 绘制表格 效果图: 二,创建步骤: 1,创建布局: activity_main中的布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:

  • Android编程绘制圆形图片的方法

    本文实例讲述了Android编程绘制圆形图片的方法.分享给大家供大家参考,具体如下: 效果图如下: 第一步:新建RoundView自定义控件继承View package com.rong.activity; import com.rong.test.R; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.grap

  • Android QQ登录界面绘制代码

    先看看效果图: 首先过程中碰到的几个问题: 1.对 EditText 进行自定义背景 2.运行时自动 EditText 自动获得焦点 3.在获得焦点时即清空 hint ,而不是输入后清空 4.清空按钮的出现时机(在得到焦点并且有输入内容时) ---  这些问题都有一一解决 --- 以下是代码: 布局 fragment_main(问题2) <!-- android:focusable="true" android:focusableInTouchMode="true&qu

  • Android编程开发之在Canvas中利用Path绘制基本图形(圆形,矩形,椭圆,三角形等)

    本文实例讲述了Android编程开发之在Canvas中利用Path绘制基本图形的方法.分享给大家供大家参考,具体如下: 在Android中绘制基本的集合图形,本程序就是自定义一个View组件,程序重写该View组件的onDraw(Canvase)方法,然后在该Canvas上绘制大量的基本的集合图形. 直接上代码: 1.自定义的View组件代码: package com.infy.configuration; import android.content.Context; import andro

  • Android开发 OpenGL ES绘制3D 图形实例详解

    OpenGL ES是 OpenGL三维图形API 的子集,针对手机.PDA和游戏主机等嵌入式设备而设计. Ophone目前支持OpenGL ES 1.0 ,OpenGL ES 1.0 是以 OpenGL 1.3 规范为基础的,OpenGL ES 1.1 是以 OpenGL 1.5 规范为基础的.本文主要介绍利用OpenGL ES绘制图形方面的基本步骤. 本文内容由三部分构成.首先通过EGL获得OpenGL ES的编程接口;其次介绍构建3D程序的基本概念;最后是一个应用程序示例. OpenGL E

  • Android百度地图实现搜索和定位及自定义图标绘制并点击时弹出泡泡

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二.编写MyApplication类 public class MyApplication extends Application { private static MyApplication mInstance = null; public boolean m_bKeyRight = true; pu

  • Android开发笔记之:在ImageView上绘制圆环的实现方法

    绘制圆环其实很简单,有大概以下三种思路. 这里先说网上提到的一种方法.思路是先绘制内圆,然后绘制圆环(圆环的宽度就是paint设置的paint.setStrokeWidth的宽度),最后绘制外圆.请看核心源码: 复制代码 代码如下: <SPAN xmlns="http://www.w3.org/1999/xhtml">package yan.guoqi.rectphoto;import android.content.Context;import android.graph

  • Android自定义View之继承TextView绘制背景

    本文实例为大家分享了TextView绘制背景的方法,供大家参考,具体内容如下 效果: 实现流程: 1.初始化:对画笔进行设置 mPaintIn = new Paint(); mPaintIn.setAntiAlias(true); mPaintIn.setDither(true); mPaintIn.setStyle(Paint.Style.FILL); mPaintIn.setColor(getResources().getColor(R.color.colorPrimary)); mPain

随机推荐