IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    自定义View——雷达图(蜘蛛网图)

    summer发表于 2016-06-30 15:13:09
    love 0

    效果图:

    如果不熟悉View的绘制流程,请先查看我之前的文章
    Android坐标系与View绘制流程

    一、获取View宽高以及cos、sin

    在onSizeChanged函数中,可以获取当前View的宽高以及根据padding值计算出的实际绘制区域的宽高,同时进行出雷达图得半径设置并通过PathMeasure类的
    getPosTan 方法获得此任意正多边形各角坐标的余弦值、正弦值。

    因为在之前的文章中并没有介绍getPosTan方法,这里对其进行一个简单的介绍。

    boolean getPosTan (float distance, float[] pos, float[] tan)

    • distance为距离当前path起点的距离,取值范围为0到path的长度。
    • pos 如果不为null,则返回path当前距离的位置坐标,pos[0] = x,pos[1] = y 。
    • tan 如果不为null,则返回当前位置坐标的切线,tan[0] = x, tan[1] = y 。
    • 返回值为boolean,true表示成功,数据会存入pas、tan,反之则为失败,数据也不会存入pas、tan。

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    mViewWidth = w;
    mViewHeight = h;
    mWidth = mViewWidth - getPaddingLeft() - getPaddingRight();
    mHeight = mViewHeight - getPaddingTop() - getPaddingBottom();
    radius = Math.min(mWidth,mHeight)*0.35f;
    ...
    //增加圆形路径,起点从90度开始,顺时针旋转
    mPath.addCircle(0,0,mRadarAxisData.getAxisLength(), Path.Direction.CW);
    //为PathMeasure设置路径
    measure.setPath(mPath,true);

    float[] cosArray = new float[mRadarAxisData.getTypes().length];
    float[] sinArray = new float[mRadarAxisData.getTypes().length];
    for (int i=0; i<mRadarAxisData.getTypes().length; i++){
    //获取Path距离起点当前距离的坐标,以及切线
    measure.getPosTan((float) (Math.PI*2*mRadarAxisData.getAxisLength()*i/
    mRadarAxisData.getTypes().length),pos,tan);
    //装填cos、sin
    cosArray[i] = tan[0];
    sinArray[i] = tan[1];
    }
    mPath.reset();
    ...
    }

    二、绘制坐标网络

    雷达图的坐标网络(即正多边形)的绘制将在onDraw函数中进行。* 首先通过画布缩放的方式绘制一圈圈的网格。

    for (int i=0; i<number; i++){
    canvas.save();
    //缩放画布
    canvas.scale(1-i/number,1-i/number);
    移动至第一点
    mPathRing.moveTo(0,radarAxisData.getAxisLength());
    //连接个点
    if (radarAxisData.getTypes()!=null)
    for (int j=0; j<radarAxisData.getTypes().length; j++){
    mPathRing.lineTo(radarAxisData.getAxisLength()*radarAxisData.getCosArray()[j],
    radarAxisData.getAxisLength()*radarAxisData.getSinArray()[j]);
    }
    //闭合路径
    mPathRing.close();
    //绘制路径
    canvas.drawPath(mPathRing,mPaintLine);
    mPathRing.reset();
    canvas.restore();
    }

    • 然后是绘制正多边形各角的连线以及对应的名称

    if (radarAxisData.getTypes()!=null)
    for (int j=0; j<radarAxisData.getTypes().length; j++){
    //连接各点
    mPathLine.moveTo(0,0);
    mPathLine.lineTo(radarAxisData.getAxisLength()*radarAxisData.getCosArray()[j],
    radarAxisData.getAxisLength()*radarAxisData.getSinArray()[j]);
    //绘制文字
    canvas.save();
    canvas.rotate(180);
    //设置文字坐标
    mPointF.y = -radarAxisData.getAxisLength()*radarAxisData.getSinArray()[j]*1.1f;
    mPointF.x = -radarAxisData.getAxisLength()*radarAxisData.getCosArray()[j]*1.1f;
    //根据cos值,判断文字位置,设置居左、居中、居右
    if (radarAxisData.getCosArray()[j]>0.2){
    textCenter(new String[]{radarAxisData.getTypes()[j]},mPaintText,canvas,mPointF, Paint.Align.RIGHT);
    }else if (radarAxisData.getCosArray()[j]<-0.2){
    textCenter(new String[]{radarAxisData.getTypes()[j]},mPaintText,canvas,mPointF, Paint.Align.LEFT);
    }else {
    textCenter(new String[]{radarAxisData.getTypes()[j]},mPaintText,canvas,mPointF, Paint.Align.CENTER);
    }
    canvas.restore();
    }
    mPathLine.close();
    canvas.drawPath(mPathLine,mPaintLine);
    mPathLine.reset();
    canvas.restore();

    因为文字的方向性,所以必须在绘制的过程中旋转回正方向。同时通过判断cos值的大小,来设置文字的居左、居中、居右。

    • 最后给网格绘制刻度,因为y轴正方向是向下的,所以在设置坐标是需这只负值。

    //设置小数点位数
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setMaximumFractionDigits(radarAxisData.getDecimalPlaces());
    if (radarAxisData.getIsTextSize())
    for (int i=1; i<number+1; i++){
    mPointF.x = 0;
    mPointF.y = -radarAxisData.getAxisLength()*(1-i/number);
    //绘制文字
    canvas.drawText(numberFormat.format(radarAxisData.getMinimum()+radarAxisData.getInterval()*(number-i))
    +" "+radarAxisData.getUnit(), mPointF.x, mPointF.y, mPaintText);
    }

    三、绘制数据覆盖区域

    绘制实际数据也是在onDraw中进行的,只需计算出各个数据在画布上的实际长度,再乘以相应的cos、sin之后,就可以获得相应的坐标点。位移需要注意的是,绘制的点数需要以传入的各角的字符串的数量为准,同时在数据为空的情况下,设置数据为0即可。

    @Override
    public void drawGraph(Canvas canvas, float animatedValue) {
    for (int i=0 ; i<radarAxisData.getTypes().length; i++){
    if (i<radarData.getValue().size()) {
    float value = radarData.getValue().get(i);
    float yValue = (value-radarAxisData.getMinimum())*radarAxisData.getAxisScale();
    if (i==0){
    //移动至第一点
    mPath.moveTo(yValue*radarAxisData.getCosArray()[i],yValue*radarAxisData.getSinArray()[i]);
    }else {
    //连接其余各点
    mPath.lineTo(yValue*radarAxisData.getCosArray()[i],yValue*radarAxisData.getSinArray()[i]);
    }
    }else {
    mPath.lineTo(0,0);
    }
    }
    mPath.close();
    //填充区域绘制
    mPaintFill.setColor(radarData.getColor());
    mPaintFill.setAlpha(radarData.getAlpha());
    canvas.drawPath(mPath,mPaintFill);
    //描线路径绘制
    mPaintStroke.setColor(radarData.getColor());
    canvas.drawPath(mPath,mPaintStroke);
    mPath.reset();
    }

    四、适应wrap_content

    View原有的 onMeasure 函数中,使用了 getDefaultSize 方法,来根据不同的测量方式,生成View的实际宽高。来看下
    getDefaultSize 的源码 :

    public static int getDefaultSize(int size, int measureSpec) {
    int result = size;
    int specMode = MeasureSpec.getMode(measureSpec);//获取测量方式
    int specSize = MeasureSpec.getSize(measureSpec);//获取测量数值
    switch (specMode) {
    case MeasureSpec.UNSPECIFIED:
    result = size;
    break;
    case MeasureSpec.AT_MOST:
    case MeasureSpec.EXACTLY:
    result = specSize;
    break;
    }
    return result;
    }

    可以看出 getDefaultSize方法 中,对于xml中设置wrap_content时,使用的 AT_MOST 测量方法并没有做相应处理。

    View中还有另一个方法 resolveSizeAndState 可以满足我们对 AT_MOST 情况下View宽高的需求。源码 :

    public static int resolveSizeAndState(int size, int measureSpec, int childMeasuredState) {
    final int specMode = MeasureSpec.getMode(measureSpec);
    final int specSize = MeasureSpec.getSize(measureSpec);
    final int result;
    switch (specMode) {
    case MeasureSpec.AT_MOST:
    if (specSize < size) {
    result = specSize | MEASURED_STATE_TOO_SMALL;
    } else {
    result = size;
    }
    break;
    case MeasureSpec.EXACTLY:
    result = specSize;
    break;
    case MeasureSpec.UNSPECIFIED:
    default:
    result = size;
    }
    return result | (childMeasuredState & MEASURED_STATE_MASK);
    }

    • resolveSizeAndState 方法中,在 AT_MOST 测量模式下。如果
      onMeasure
      传递的measureSpec值小于,你给定的size值,则会使用
      MEASURED_STATE_TOO_SMALL(值为 0x01000000 )整理后的specSize值;如果你给定的size更小,那么就是用你的size作为返回。最后通过与MEASURED_STATE_MASK合成出返回值。
    • 另两种情况下和之前的 getDefaultSize 时相同,在
      EXACTLY
      时,即给定宽高值得情况下,使用了 onMeasure 中获取的值。

    • 而在 UNSPECIFIED 时,即View想要多大就多大的情况下,使用了给定的size作为返回值,而我们没有子View,childMeasuredState设置为0即可。最后通过与MEASURED_STATE_MASK合成出返回值。

    现在使用 resolveSizeAndState 方法只差size值了,获取size值的方法与之前的
    PieChart
    类似,通过计算需要绘制文字的宽高以及数量,来计算出size值。

    public int getCurrentWidth() {
    int wrapSize;
    if (mDataList!=null&&mDataList.size()>1&&mRadarAxisData.getTypes().length>1){
    //设置小数位数
    NumberFormat numberFormat =NumberFormat.getPercentInstance();
    numberFormat.setMinimumFractionDigits(mRadarAxisData.getDecimalPlaces());
    paintText.setStrokeWidth(mRadarAxisData.getPaintWidth());
    paintText.setTextSize(mRadarAxisData.getTextSize());
    //获取FontMetrics
    Paint.FontMetrics fontMetrics= paintText.getFontMetrics();
    float top = fontMetrics.top;//获取baseline之上高度
    float bottom = fontMetrics.bottom; //获取baseline之下高度
    float webWidth = (bottom-top)*(float) Math.ceil((mRadarAxisData.getMaximum()-mRadarAxisData.getMinimum())
    /mRadarAxisData.getInterval());//计算单个高度*数量
    float nameWidth = paintText.measureText(mRadarAxisData.getTypes()[0]);//计算正多边形各角字符的长度
    wrapSize = (int) (webWidth*2+nameWidth*1.1);
    }else {
    wrapSize = 0;
    }
    return wrapSize;
    }

    由代码可以看出通过计算出刻度值的高度与各角字符的高度来合成Size值。

    最后只要在 onMeasure 中使用size值,即可实现雷达图 wrap_content 效果。与getSuggestedMinimumWidth()获取的值相比较是为了防止,size过小而出现以外,虽然此情况出现的几率并不大。

    http://www.cunet.com.cn/e/space/?userid=3482465&nra.aspx

    http://www.cunet.com.cn/e/space/?userid=3482653&kku.aspx

    http://www.cunet.com.cn/e/space/?userid=3482655&mjl.aspx

    http://www.cunet.com.cn/e/space/?userid=3482656&dzr.aspx

    http://www.cunet.com.cn/e/space/?userid=3482657&jom.aspx

    http://www.cunet.com.cn/e/space/?userid=3482658&ukn.aspx

    http://www.cunet.com.cn/e/space/?userid=3482659&btt.aspx

    http://www.cunet.com.cn/e/space/?userid=3482661&dmb.aspx

    http://www.cunet.com.cn/e/space/?userid=3482663&qgm.aspx

    http://www.cunet.com.cn/e/space/?userid=3482664&djj.aspx

    http://www.cunet.com.cn/e/space/?userid=3482665&sit.aspx

    http://www.cunet.com.cn/e/space/?userid=3482666&agq.aspx

    http://www.cunet.com.cn/e/space/?userid=3482667&btz.aspx

    http://www.cunet.com.cn/e/space/?userid=3482668&akz.aspx

    http://www.cunet.com.cn/e/space/?userid=3482670&twr.aspx

    http://www.cunet.com.cn/e/space/?userid=3482671&jjo.aspx

    http://www.cunet.com.cn/e/space/?userid=3482672&atu.aspx

    http://www.cunet.com.cn/e/space/?userid=3482673&xme.aspx

    http://www.cunet.com.cn/e/space/?userid=3482674&qbg.aspx

    http://www.cunet.com.cn/e/space/?userid=3482676&xcg.aspx

    http://www.cunet.com.cn/e/space/?userid=3482677&vpc.aspx

    http://www.cunet.com.cn/e/space/?userid=3482678&ccd.aspx

    http://www.cunet.com.cn/e/space/?userid=3482679&wqq.aspx

    http://www.cunet.com.cn/e/space/?userid=3482765&xnv.aspx

    http://www.cunet.com.cn/e/space/?userid=3482768&jql.aspx

    http://www.cunet.com.cn/e/space/?userid=3482770&rhf.aspx

    http://www.cunet.com.cn/e/space/?userid=3482772&lch.aspx

    http://www.cunet.com.cn/e/space/?userid=3482774&uyr.aspx

    http://www.cunet.com.cn/e/space/?userid=3482777&jdl.aspx

    http://www.cunet.com.cn/e/space/?userid=3482779&ucn.aspx

    http://www.cunet.com.cn/e/space/?userid=3482781&oms.aspx

    http://www.cunet.com.cn/e/space/?userid=3482785&jin.aspx

    http://www.cunet.com.cn/e/space/?userid=3482788&hpw.aspx

    http://www.cunet.com.cn/e/space/?userid=3482790&nkh.aspx

    http://www.cunet.com.cn/e/space/?userid=3482794&fzw.aspx

    http://www.cunet.com.cn/e/space/?userid=3482796&ldp.aspx

    http://www.cunet.com.cn/e/space/?userid=3482799&fgx.aspx

    http://www.cunet.com.cn/e/space/?userid=3482802&pql.aspx

    http://www.cunet.com.cn/e/space/?userid=3482804&jnf.aspx

    http://www.cunet.com.cn/e/space/?userid=3482807&dxb.aspx

    http://www.cunet.com.cn/e/space/?userid=3482811&wrg.aspx

    http://www.cunet.com.cn/e/space/?userid=3482812&osa.aspx

    http://www.cunet.com.cn/e/space/?userid=3482816&ysu.aspx

    http://www.cunet.com.cn/e/space/?userid=3482818&rxx.aspx

    http://www.cunet.com.cn/e/space/?userid=3482821&ugd.aspx

    http://www.cunet.com.cn/e/space/?userid=3482825&dnw.aspx

    http://www.cunet.com.cn/e/space/?userid=3482829&chy.aspx

    http://www.cunet.com.cn/e/space/?userid=3482837&hkl.aspx

    http://www.cunet.com.cn/e/space/?userid=3482846&ula.aspx

    http://www.cunet.com.cn/e/space/?userid=3482853&vno.aspx

    http://www.cunet.com.cn/e/space/?userid=3482864&ufz.aspx

    http://www.cunet.com.cn/e/space/?userid=3482872&gmq.aspx

    http://www.cunet.com.cn/e/space/?userid=3482879&laj.aspx

    http://www.cunet.com.cn/e/space/?userid=3482885&kwl.aspx

    http://www.cunet.com.cn/e/space/?userid=3482893&tcx.aspx

    http://www.cunet.com.cn/e/space/?userid=3482902&eer.aspx

    http://www.cunet.com.cn/e/space/?userid=3482910&mqc.aspx

    http://www.cunet.com.cn/e/space/?userid=3482920&nfy.aspx

    http://www.cunet.com.cn/e/space/?userid=3482927&hdk.aspx

    http://www.cunet.com.cn/e/space/?userid=3482936&xzv.aspx

    http://www.cunet.com.cn/e/space/?userid=3482945&ijb.aspx

    http://www.cunet.com.cn/e/space/?userid=3482952&sev.aspx

    http://www.cunet.com.cn/e/space/?userid=3482964&egx.aspx

    http://www.cunet.com.cn/e/space/?userid=3482970&duj.aspx

    http://www.cunet.com.cn/e/space/?userid=3482979&juq.aspx

    http://www.cunet.com.cn/e/space/?userid=3482990&kec.aspx

    http://www.cunet.com.cn/e/space/?userid=3482998&ewo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483009&czo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483017&lea.aspx

    http://www.cunet.com.cn/e/space/?userid=3483025&mwr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483031&dyr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483038&hzr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483043&oep.aspx

    http://www.cunet.com.cn/e/space/?userid=3483051&pgs.aspx

    http://www.cunet.com.cn/e/space/?userid=3483057&buk.aspx

    http://www.cunet.com.cn/e/space/?userid=3483062&vmx.aspx

    http://www.cunet.com.cn/e/space/?userid=3483071&nnr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483076&okf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483081&gmq.aspx

    http://www.cunet.com.cn/e/space/?userid=3483091&hpj.aspx

    http://www.cunet.com.cn/e/space/?userid=3483097&mlf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483101&tqh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483110&rrm.aspx

    http://www.cunet.com.cn/e/space/?userid=3483115&wsb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483124&jwk.aspx

    http://www.cunet.com.cn/e/space/?userid=3483131&efk.aspx

    http://www.cunet.com.cn/e/space/?userid=3483137&one.aspx

    http://www.cunet.com.cn/e/space/?userid=3483142&oyz.aspx

    http://www.cunet.com.cn/e/space/?userid=3483150&uwh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483155&wqc.aspx

    http://www.cunet.com.cn/e/space/?userid=3483161&nfn.aspx

    http://www.cunet.com.cn/e/space/?userid=3483169&wim.aspx

    http://www.cunet.com.cn/e/space/?userid=3483175&uvh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483181&qoh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483188&dzy.aspx

    http://www.cunet.com.cn/e/space/?userid=3483195&ykf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483199&qlw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483208&fhb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483213&lhw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483218&hgw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483228&mhj.aspx

    http://www.cunet.com.cn/e/space/?userid=3483233&xoe.aspx

    http://www.cunet.com.cn/e/space/?userid=3483238&wfa.aspx

    http://www.cunet.com.cn/e/space/?userid=3483244&ved.aspx

    http://www.cunet.com.cn/e/space/?userid=3483249&dyv.aspx

    http://www.cunet.com.cn/e/space/?userid=3483254&tmu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483260&mrt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483266&ewo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483273&nvb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483277&dqb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483283&njt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483289&gph.aspx

    http://www.cunet.com.cn/e/space/?userid=3483296&tcx.aspx

    http://www.cunet.com.cn/e/space/?userid=3483302&kwu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483308&cjb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483315&jfa.aspx

    http://www.cunet.com.cn/e/space/?userid=3483322&unm.aspx

    http://www.cunet.com.cn/e/space/?userid=3483327&uuf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483334&yqt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483341&wob.aspx

    http://www.cunet.com.cn/e/space/?userid=3483348&zcw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483356&vwe.aspx

    http://www.cunet.com.cn/e/space/?userid=3483363&wyx.aspx

    http://www.cunet.com.cn/e/space/?userid=3483369&dbm.aspx

    http://www.cunet.com.cn/e/space/?userid=3483375&jdw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483383&vdt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483387&dlg.aspx

    http://www.cunet.com.cn/e/space/?userid=3483394&yvp.aspx

    http://www.cunet.com.cn/e/space/?userid=3483402&zaf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483407&rky.aspx

    http://www.cunet.com.cn/e/space/?userid=3483413&tyz.aspx

    http://www.cunet.com.cn/e/space/?userid=3483421&sqt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483426&ngj.aspx

    http://www.cunet.com.cn/e/space/?userid=3483432&iqh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483439&tsh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483445&fof.aspx

    http://www.cunet.com.cn/e/space/?userid=3483452&nme.aspx

    http://www.cunet.com.cn/e/space/?userid=3483459&xjo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483465&ccu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483473&uff.aspx

    http://www.cunet.com.cn/e/space/?userid=3483478&vni.aspx

    http://www.cunet.com.cn/e/space/?userid=3483484&xqi.aspx

    http://www.cunet.com.cn/e/space/?userid=3483490&stb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483497&gfd.aspx

    http://www.cunet.com.cn/e/space/?userid=3483502&frf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483509&chf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483516&nxr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483523&qmb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483528&zku.aspx

    http://www.cunet.com.cn/e/space/?userid=3483537&cqr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483542&syh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483549&vvt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483556&jqt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483561&aah.aspx

    http://www.cunet.com.cn/e/space/?userid=3483567&hsp.aspx

    http://www.cunet.com.cn/e/space/?userid=3483575&rrz.aspx

    http://www.cunet.com.cn/e/space/?userid=3483580&rsq.aspx

    http://www.cunet.com.cn/e/space/?userid=3483587&qrn.aspx

    http://www.cunet.com.cn/e/space/?userid=3483594&fpy.aspx

    http://www.cunet.com.cn/e/space/?userid=3483600&xzg.aspx

    http://www.cunet.com.cn/e/space/?userid=3483605&fue.aspx

    http://www.cunet.com.cn/e/space/?userid=3483613&wqs.aspx

    http://www.cunet.com.cn/e/space/?userid=3483619&wwd.aspx

    http://www.cunet.com.cn/e/space/?userid=3483625&ltu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483630&qmb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483637&bwp.aspx

    http://www.cunet.com.cn/e/space/?userid=3483644&ytl.aspx

    http://www.cunet.com.cn/e/space/?userid=3483649&atm.aspx

    http://www.cunet.com.cn/e/space/?userid=3483655&jkg.aspx

    http://www.cunet.com.cn/e/space/?userid=3483662&mtn.aspx

    http://www.cunet.com.cn/e/space/?userid=3483668&pmr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483675&dus.aspx

    http://www.cunet.com.cn/e/space/?userid=3483685&jjx.aspx

    http://www.cunet.com.cn/e/space/?userid=3483693&zxa.aspx

    http://www.cunet.com.cn/e/space/?userid=3483701&vbw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483709&iac.aspx

    http://www.cunet.com.cn/e/space/?userid=3483716&ncr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483724&vlh.aspx

    http://www.cunet.com.cn/e/space/?userid=3483733&ffg.aspx

    http://www.cunet.com.cn/e/space/?userid=3483742&kmo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483751&khr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483761&nzq.aspx

    http://www.cunet.com.cn/e/space/?userid=3483768&pvo.aspx

    http://www.cunet.com.cn/e/space/?userid=3483779&dtk.aspx

    http://www.cunet.com.cn/e/space/?userid=3483787&skl.aspx

    http://www.cunet.com.cn/e/space/?userid=3483795&qqf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483805&rmy.aspx

    http://www.cunet.com.cn/e/space/?userid=3483814&fwx.aspx

    http://www.cunet.com.cn/e/space/?userid=3483822&rnt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483832&rvu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483840&yws.aspx

    http://www.cunet.com.cn/e/space/?userid=3483847&aor.aspx

    http://www.cunet.com.cn/e/space/?userid=3483857&bnb.aspx

    http://www.cunet.com.cn/e/space/?userid=3483866&opr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483873&ocw.aspx

    http://www.cunet.com.cn/e/space/?userid=3483883&wid.aspx

    http://www.cunet.com.cn/e/space/?userid=3483891&bpc.aspx

    http://www.cunet.com.cn/e/space/?userid=3483901&nib.aspx

    http://www.cunet.com.cn/e/space/?userid=3483909&kmu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483918&zez.aspx

    http://www.cunet.com.cn/e/space/?userid=3483928&dzr.aspx

    http://www.cunet.com.cn/e/space/?userid=3483935&gqf.aspx

    http://www.cunet.com.cn/e/space/?userid=3483945&xnl.aspx

    http://www.cunet.com.cn/e/space/?userid=3483954&aaj.aspx

    http://www.cunet.com.cn/e/space/?userid=3483961&hvu.aspx

    http://www.cunet.com.cn/e/space/?userid=3483973&cdt.aspx

    http://www.cunet.com.cn/e/space/?userid=3483981&brq.aspx

    http://www.cunet.com.cn/e/space/?userid=3483990&uet.aspx

    http://www.cunet.com.cn/e/space/?userid=3483999&qzj.aspx

    http://www.cunet.com.cn/e/space/?userid=3484008&ald.aspx

    http://www.cunet.com.cn/e/space/?userid=3484019&ham.aspx

    http://www.cunet.com.cn/e/space/?userid=3484026&mzb.aspx

    http://www.cunet.com.cn/e/space/?userid=3484038&taz.aspx

    http://www.cunet.com.cn/e/space/?userid=3484046&wxy.aspx

    http://www.cunet.com.cn/e/space/?userid=3484054&afq.aspx

    http://www.cunet.com.cn/e/space/?userid=3484064&yuv.aspx

    http://www.cunet.com.cn/e/space/?userid=3484072&wce.aspx

    http://www.cunet.com.cn/e/space/?userid=3484083&fek.aspx

    http://www.cunet.com.cn/e/space/?userid=3484092&phy.aspx

    http://www.cunet.com.cn/e/space/?userid=3484100&rnq.aspx

    http://www.cunet.com.cn/e/space/?userid=3484109&qhz.aspx

    http://www.cunet.com.cn/e/space/?userid=3484119&rrv.aspx

    http://www.cunet.com.cn/e/space/?userid=3484130&rmm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484138&ilg.aspx

    http://www.cunet.com.cn/e/space/?userid=3484148&eok.aspx

    http://www.cunet.com.cn/e/space/?userid=3484157&odf.aspx

    http://www.cunet.com.cn/e/space/?userid=3484166&qit.aspx

    http://www.cunet.com.cn/e/space/?userid=3484177&uol.aspx

    http://www.cunet.com.cn/e/space/?userid=3484184&eue.aspx

    http://www.cunet.com.cn/e/space/?userid=3484195&rvx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484202&fgj.aspx

    http://www.cunet.com.cn/e/space/?userid=3484213&asi.aspx

    http://www.cunet.com.cn/e/space/?userid=3484222&okm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484230&bpw.aspx

    http://www.cunet.com.cn/e/space/?userid=3484241&bkg.aspx

    http://www.cunet.com.cn/e/space/?userid=3484250&lvl.aspx

    http://www.cunet.com.cn/e/space/?userid=3484261&grl.aspx

    http://www.cunet.com.cn/e/space/?userid=3484271&ywo.aspx

    http://www.cunet.com.cn/e/space/?userid=3484282&ibx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484290&dho.aspx

    http://www.cunet.com.cn/e/space/?userid=3484301&mhx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484311&xct.aspx

    http://www.cunet.com.cn/e/space/?userid=3484321&huj.aspx

    http://www.cunet.com.cn/e/space/?userid=3484331&drj.aspx

    http://www.cunet.com.cn/e/space/?userid=3484339&vsk.aspx

    http://www.cunet.com.cn/e/space/?userid=3484351&nrw.aspx

    http://www.cunet.com.cn/e/space/?userid=3484359&ong.aspx

    http://www.cunet.com.cn/e/space/?userid=3484367&zra.aspx

    http://www.cunet.com.cn/e/space/?userid=3484378&zbv.aspx

    http://www.cunet.com.cn/e/space/?userid=3484386&zyt.aspx

    http://www.cunet.com.cn/e/space/?userid=3484398&gjx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484406&nge.aspx

    http://www.cunet.com.cn/e/space/?userid=3484415&vng.aspx

    http://www.cunet.com.cn/e/space/?userid=3484426&mfm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484434&dgp.aspx

    http://www.cunet.com.cn/e/space/?userid=3484444&sjn.aspx

    http://www.cunet.com.cn/e/space/?userid=3484452&qyw.aspx

    http://www.cunet.com.cn/e/space/?userid=3484462&xfz.aspx

    http://www.cunet.com.cn/e/space/?userid=3484471&vgr.aspx

    http://www.cunet.com.cn/e/space/?userid=3484478&enn.aspx

    http://www.cunet.com.cn/e/space/?userid=3484490&gpa.aspx

    http://www.cunet.com.cn/e/space/?userid=3484498&hzl.aspx

    http://www.cunet.com.cn/e/space/?userid=3484508&jdk.aspx

    http://www.cunet.com.cn/e/space/?userid=3484518&fdx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484525&tfv.aspx

    http://www.cunet.com.cn/e/space/?userid=3484536&sxc.aspx

    http://www.cunet.com.cn/e/space/?userid=3484544&iju.aspx

    http://www.cunet.com.cn/e/space/?userid=3484556&zzf.aspx

    http://www.cunet.com.cn/e/space/?userid=3484564&pxe.aspx

    http://www.cunet.com.cn/e/space/?userid=3484575&pvr.aspx

    http://www.cunet.com.cn/e/space/?userid=3484583&eaf.aspx

    http://www.cunet.com.cn/e/space/?userid=3484591&qwm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484601&jzk.aspx

    http://www.cunet.com.cn/e/space/?userid=3484608&her.aspx

    http://www.cunet.com.cn/e/space/?userid=3484619&sit.aspx

    http://www.cunet.com.cn/e/space/?userid=3484627&abh.aspx

    http://www.cunet.com.cn/e/space/?userid=3484637&hdd.aspx

    http://www.cunet.com.cn/e/space/?userid=3484645&ise.aspx

    http://www.cunet.com.cn/e/space/?userid=3484655&wyu.aspx

    http://www.cunet.com.cn/e/space/?userid=3484666&zxm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484673&ynp.aspx

    http://www.cunet.com.cn/e/space/?userid=3484684&fqh.aspx

    http://www.cunet.com.cn/e/space/?userid=3484693&wmg.aspx

    http://www.cunet.com.cn/e/space/?userid=3484701&kro.aspx

    http://www.cunet.com.cn/e/space/?userid=3484713&euw.aspx

    http://www.cunet.com.cn/e/space/?userid=3484721&gxr.aspx

    http://www.cunet.com.cn/e/space/?userid=3484730&fko.aspx

    http://www.cunet.com.cn/e/space/?userid=3484740&emm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484748&ehy.aspx

    http://www.cunet.com.cn/e/space/?userid=3484759&kyi.aspx

    http://www.cunet.com.cn/e/space/?userid=3484768&fzm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484780&ulr.aspx

    http://www.cunet.com.cn/e/space/?userid=3484788&ago.aspx

    http://www.cunet.com.cn/e/space/?userid=3484796&irx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484807&heh.aspx

    http://www.cunet.com.cn/e/space/?userid=3484815&vsz.aspx

    http://www.cunet.com.cn/e/space/?userid=3484824&cau.aspx

    http://www.cunet.com.cn/e/space/?userid=3484835&huh.aspx

    http://www.cunet.com.cn/e/space/?userid=3484843&bah.aspx

    http://www.cunet.com.cn/e/space/?userid=3484851&hdf.aspx

    http://www.cunet.com.cn/e/space/?userid=3484861&qbe.aspx

    http://www.cunet.com.cn/e/space/?userid=3484869&wnf.aspx

    http://www.cunet.com.cn/e/space/?userid=3484881&zpl.aspx

    http://www.cunet.com.cn/e/space/?userid=3484889&bdx.aspx

    http://www.cunet.com.cn/e/space/?userid=3484902&ypb.aspx

    http://www.cunet.com.cn/e/space/?userid=3484910&tog.aspx

    http://www.cunet.com.cn/e/space/?userid=3484918&dss.aspx

    http://www.cunet.com.cn/e/space/?userid=3484929&ccp.aspx

    http://www.cunet.com.cn/e/space/?userid=3484937&xee.aspx

    http://www.cunet.com.cn/e/space/?userid=3484947&awv.aspx

    http://www.cunet.com.cn/e/space/?userid=3484956&eet.aspx

    http://www.cunet.com.cn/e/space/?userid=3484967&scn.aspx

    http://www.cunet.com.cn/e/space/?userid=3484976&nhz.aspx

    http://www.cunet.com.cn/e/space/?userid=3484984&kwm.aspx

    http://www.cunet.com.cn/e/space/?userid=3484996&zwg.aspx

    http://www.cunet.com.cn/e/space/?userid=3485003&juk.aspx

    http://www.cunet.com.cn/e/space/?userid=3485013&hxd.aspx

    http://www.cunet.com.cn/e/space/?userid=3485023&ehz.aspx

    http://www.cunet.com.cn/e/space/?userid=3485032&skt.aspx

    http://www.cunet.com.cn/e/space/?userid=3485042&yek.aspx

    http://www.cunet.com.cn/e/space/?userid=3485050&kby.aspx

    http://www.cunet.com.cn/e/space/?userid=3485060&byo.aspx

    http://www.cunet.com.cn/e/space/?userid=3485069&ols.aspx

    http://www.cunet.com.cn/e/space/?userid=3485079&jkr.aspx

    http://www.cunet.com.cn/e/space/?userid=3485089&aio.aspx

    http://www.cunet.com.cn/e/space/?userid=3485096&fdi.aspx

    http://www.cunet.com.cn/e/space/?userid=3485107&iur.aspx

    http://www.cunet.com.cn/e/space/?userid=3485115&ovg.aspx

    http://www.cunet.com.cn/e/space/?userid=3485126&bky.aspx

    http://www.cunet.com.cn/e/space/?userid=3485136&jod.aspx

    http://www.cunet.com.cn/e/space/?userid=3485144&lqh.aspx

    http://www.cunet.com.cn/e/space/?userid=3485155&fsl.aspx

    http://www.cunet.com.cn/e/space/?userid=3485165&vck.aspx

    http://www.cunet.com.cn/e/space/?userid=3485176&bii.aspx

    http://www.cunet.com.cn/e/space/?userid=3485185&lyb.aspx

    http://www.cunet.com.cn/e/space/?userid=3485189&agf.aspx

    http://www.cunet.com.cn/e/space/?userid=3485193&evy.aspx

    http://www.cunet.com.cn/e/space/?userid=3485195&rgg.aspx

    http://www.cunet.com.cn/e/space/?userid=3485198&ycv.aspx

    http://www.cunet.com.cn/e/space/?userid=3485200&rgd.aspx

    http://www.cunet.com.cn/e/space/?userid=3485204&jwc.aspx

    http://www.cunet.com.cn/e/space/?userid=3485207&cxg.aspx

    http://www.cunet.com.cn/e/space/?userid=3485211&nvk.aspx

    http://www.cunet.com.cn/e/space/?userid=3485213&pcz.aspx

    http://www.cunet.com.cn/e/space/?userid=3485216&ydy.aspx

    http://www.cunet.com.cn/e/space/?userid=3485222&cte.aspx

    http://www.cunet.com.cn/e/space/?userid=3485229&wih.aspx

    http://www.cunet.com.cn/e/space/?userid=3485239&ijn.aspx

    http://www.cunet.com.cn/e/space/?userid=3485247&cac.aspx

    http://www.cunet.com.cn/e/space/?userid=3485257&bfr.aspx

    http://www.cunet.com.cn/e/space/?userid=3485266&uos.aspx

    http://www.cunet.com.cn/e/space/?userid=3485274&sky.aspx

    http://www.cunet.com.cn/e/space/?userid=3485285&fes.aspx

    http://www.cunet.com.cn/e/space/?userid=3485294&ktj.aspx

    http://www.cunet.com.cn/e/space/?userid=3485305&rda.aspx

    http://www.cunet.com.cn/e/space/?userid=3485313&iro.aspx

    http://www.cunet.com.cn/e/space/?userid=3485322&jar.aspx

    http://www.cunet.com.cn/e/space/?userid=3485330&ghx.aspx

    http://www.cunet.com.cn/e/space/?userid=3485340&ezx.aspx

    http://www.cunet.com.cn/e/space/?userid=3485351&kkt.aspx

    http://www.cunet.com.cn/e/space/?userid=3485359&qgy.aspx

    http://www.cunet.com.cn/e/space/?userid=3485369&gcl.aspx

    http://www.cunet.com.cn/e/space/?userid=3485378&hcc.aspx

    http://www.cunet.com.cn/e/space/?userid=3485389&lyu.aspx

    http://www.cunet.com.cn/e/space/?userid=3485398&dgq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485407&jkf.aspx

    http://www.cunet.com.cn/e/space/?userid=3485419&ils.aspx

    http://www.cunet.com.cn/e/space/?userid=3485426&axd.aspx

    http://www.cunet.com.cn/e/space/?userid=3485436&rgs.aspx

    http://www.cunet.com.cn/e/space/?userid=3485447&rwl.aspx

    http://www.cunet.com.cn/e/space/?userid=3485454&lac.aspx

    http://www.cunet.com.cn/e/space/?userid=3485466&bwa.aspx

    http://www.cunet.com.cn/e/space/?userid=3485474&wtw.aspx

    http://www.cunet.com.cn/e/space/?userid=3485483&gcb.aspx

    http://www.cunet.com.cn/e/space/?userid=3485493&kyp.aspx

    http://www.cunet.com.cn/e/space/?userid=3485502&iqw.aspx

    http://www.cunet.com.cn/e/space/?userid=3485513&app.aspx

    http://www.cunet.com.cn/e/space/?userid=3485523&vnm.aspx

    http://www.cunet.com.cn/e/space/?userid=3485531&rbz.aspx

    http://www.cunet.com.cn/e/space/?userid=3485542&lwl.aspx

    http://www.cunet.com.cn/e/space/?userid=3485551&qri.aspx

    http://www.cunet.com.cn/e/space/?userid=3485560&sgf.aspx

    http://www.cunet.com.cn/e/space/?userid=3485571&xwm.aspx

    http://www.cunet.com.cn/e/space/?userid=3485579&tdr.aspx

    http://www.cunet.com.cn/e/space/?userid=3485589&ldh.aspx

    http://www.cunet.com.cn/e/space/?userid=3485600&tqv.aspx

    http://www.cunet.com.cn/e/space/?userid=3485608&hqn.aspx

    http://www.cunet.com.cn/e/space/?userid=3485620&rxt.aspx

    http://www.cunet.com.cn/e/space/?userid=3485627&gxq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485636&ndy.aspx

    http://www.cunet.com.cn/e/space/?userid=3485646&vff.aspx

    http://www.cunet.com.cn/e/space/?userid=3485657&tpb.aspx

    http://www.cunet.com.cn/e/space/?userid=3485667&kti.aspx

    http://www.cunet.com.cn/e/space/?userid=3485678&otd.aspx

    http://www.cunet.com.cn/e/space/?userid=3485689&czr.aspx

    http://www.cunet.com.cn/e/space/?userid=3485699&vhp.aspx

    http://www.cunet.com.cn/e/space/?userid=3485711&gex.aspx

    http://www.cunet.com.cn/e/space/?userid=3485719&teh.aspx

    http://www.cunet.com.cn/e/space/?userid=3485730&lxc.aspx

    http://www.cunet.com.cn/e/space/?userid=3485739&ici.aspx

    http://www.cunet.com.cn/e/space/?userid=3485748&bds.aspx

    http://www.cunet.com.cn/e/space/?userid=3485758&omh.aspx

    http://www.cunet.com.cn/e/space/?userid=3485766&lku.aspx

    http://www.cunet.com.cn/e/space/?userid=3485777&hat.aspx

    http://www.cunet.com.cn/e/space/?userid=3485785&zni.aspx

    http://www.cunet.com.cn/e/space/?userid=3485794&smi.aspx

    http://www.cunet.com.cn/e/space/?userid=3485806&fkq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485814&bvq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485827&ieh.aspx

    http://www.cunet.com.cn/e/space/?userid=3485835&gzn.aspx

    http://www.cunet.com.cn/e/space/?userid=3485846&twl.aspx

    http://www.cunet.com.cn/e/space/?userid=3485855&hcq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485863&sbd.aspx

    http://www.cunet.com.cn/e/space/?userid=3485874&owq.aspx

    http://www.cunet.com.cn/e/space/?userid=3485883&qan.aspx

    http://www.cunet.com.cn/e/space/?userid=3485894&spx.aspx

    http://www.cunet.com.cn/e/space/?userid=3485903&inu.aspx

    http://www.cunet.com.cn/e/space/?userid=3485913&rku.aspx

    http://www.cunet.com.cn/e/space/?userid=3485922&mcv.aspx

    http://www.cunet.com.cn/e/space/?userid=3485930&ebo.aspx

    http://www.cunet.com.cn/e/space/?userid=3485942&btb.aspx

    http://www.cunet.com.cn/e/space/?userid=3485950&qbs.aspx

    http://www.cunet.com.cn/e/space/?userid=3485962&cmk.aspx

    http://www.cunet.com.cn/e/space/?userid=3485971&don.aspx

    http://www.cunet.com.cn/e/space/?userid=3485982&qgn.aspx

    http://www.cunet.com.cn/e/space/?userid=3485992&bzs.aspx

    http://www.cunet.com.cn/e/space/?userid=3486002&ynm.aspx

    http://www.cunet.com.cn/e/space/?userid=3486014&kka.aspx

    http://www.cunet.com.cn/e/space/?userid=3486023&wqz.aspx

    http://www.cunet.com.cn/e/space/?userid=3486036&jvr.aspx

    http://www.cunet.com.cn/e/space/?userid=3486044&ksp.aspx

    http://www.cunet.com.cn/e/space/?userid=3486053&kxe.aspx

    http://www.cunet.com.cn/e/space/?userid=3486065&qvo.aspx

    http://www.cunet.com.cn/e/space/?userid=3486072&nok.aspx

    http://www.cunet.com.cn/e/space/?userid=3486084&cgy.aspx

    http://www.cunet.com.cn/e/space/?userid=3486092&yuc.aspx

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setMeasuredDimension(
    Math.max(getSuggestedMinimumWidth(),
    resolveSize(getCurrentWidth(),
    widthMeasureSpec)),
    Math.max(getSuggestedMinimumHeight(),
    resolveSize(getCurrentHeight(),
    heightMeasureSpec)));
    }

    五、小结

    本文详细的说明了雷达图(蜘蛛网图)的具体实现,同时介绍了View中的相关流程函数,以及 resolveSizeAndState 和
    getDefaultSize 的大致内容,以选取更合适的方法来动态的适应 wrap_content 。并且通过使用PathMeasure类的
    getPosTan 方法,更方便的获取雷达图各顶点方向的cos、sin值。

    如果在阅读过程中,有任何疑问与问题,欢迎与我联系。

    GitHub:
    https://github.com/Idtk

    博客:http://www.idtkm.com

    微博:
    http://weibo.com/Idtk

    邮箱:
    Idtkma@gmail.com

    雷达图源码



沪ICP备19023445号-2号
友情链接