CircleImageView圆形图控件+MPAndroidChart图表控件

本文介绍了如何在Android应用中使用CircleImageView控件来创建圆形头像,强调了支持库的更新和RoundedBitmapDrawable类的作用。此外,还提及了一个开源的CircleImageView库,方便快速实现圆形图像效果。对于需要更复杂图形展示的需求,可以考虑使用MPAndroidChart图表控件。

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

CircleImageView---------------------------------------------------------------------------

1.升级supportv4 最新jar包:http://download.youkuaiyun.com/detail/a704755096/9384965,使用RoundedBitmapDrawable,RoundedBitmapDrawable 是 android.support.v4.graphics.drawable 里面的一个类,用来创建简单的圆角图片。 如果只是简单的圆角展示,比如展示一个圆角头像,这个类完全可以胜任(支持正方形的原始图片,不要设置android:scaleType="fitXY")。

ImageView image = (ImageView) findViewById(R.id.imageView1); 
RoundedBitmapDrawable rbm = RoundedBitmapDrawableFactory.create(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.logo));
rbm.setCornerRadius(10);//设置圆角
rbm.setAntiAlias(true);
image.setImageDrawable(rbm);

2.开源库 github地址: https://github.com/hdodenhof/CircleImageView

A fast circular ImageView perfect for profile images. This is based on RoundedImageView from Vince Mi which itself is based on techniques recommended by Romain Guy.


MPAndroidChart ---------------------------------------------------------------------------
柱状图BarChart:
<com.github.mikephil.charting.charts.BarChart
		    android:id="@+id/chart1"
		    android:layout_width="match_parent"
		    android:layout_height="match_parent" >
private void initBarChart() {
BarChart mChart = (BarChart) findViewById(R.id.chart1);
      //  mChart.setOnChartValueSelectedListener(this);

        mChart.setDrawBarShadow(false);
        mChart.setDrawValueAboveBar(true);

        mChart.setDescription("");
     // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        mChart.setMaxVisibleValueCount(60);

        // scaling can now only be done on x- and y-axis separately
        mChart.setPinchZoom(false);

        mChart.setDrawGridBackground(false);
        // mChart.setDrawYLabels(false);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setPosition(XAxisPosition.BOTTOM);//x轴数据位置
        xAxis.setDrawGridLines(false);
        xAxis.setSpaceBetweenLabels(1);

        YAxisValueFormatter custom = new com.wlhl.hong.MyYAxisValueFormatter();
        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setLabelCount(8, false);
        leftAxis.setValueFormatter(custom);
        leftAxis.setPosition(YAxisLabelPosition.OUTSIDE_CHART);
        leftAxis.setSpaceTop(15f);

        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setDrawGridLines(false);
        rightAxis.setLabelCount(8, false);
        rightAxis.setValueFormatter(custom);
        rightAxis.setSpaceTop(15f);

        Legend l = mChart.getLegend();
        l.setPosition(LegendPosition.ABOVE_CHART_LEFT);
        l.setForm(LegendForm.SQUARE);
        l.setFormSize(0f);
        l.setTextSize(14f);
        l.setXEntrySpace(4f);
        mChart.setDragEnabled(true);//拖拽 drag	
        mChart.setScaleEnabled(true);//缩放scale
        mChart.animateX(1000); //动画animation x
        setData(12, 60);
	}
private void setData(int count, float range) {
        ArrayList<String> xVals = new ArrayList<String>();//x轴数据
        for (int i = 0; i < count; i++) {
            xVals.add(i+"");
        }

        ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>();//y轴数据

        for (int i = 0; i < count; i++) {
            float mult = (range + 1);
            float val = (float) (Math.random() * mult);
            yVals1.add(new BarEntry(val, i));
        }

        BarDataSet set1 = new BarDataSet(yVals1, "提示数据");
        set1.setBarSpacePercent(35f);
        set1.setColor(getResources().getColor(R.color.light_blue));//柱状图颜色bar color 

        ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
        dataSets.add(set1);

        BarData data = new BarData(xVals, dataSets);
        data.setValueTextSize(10f);

        mChart.setData(data);
    }


折线图LineChart:
<com.github.mikephil.charting.charts.LineChart
        android:id="@+id/chart1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
private void initLineChart() {
  LineChart mChart = (LineChart) findViewById(R.id.chart1);
//	        mChart.setOnChartValueSelectedListener(this);
	        mChart.setDrawGridBackground(false);
	        mChart.setDescription("");
	        mChart.setDrawBorders(false);

	        mChart.getAxisLeft().setDrawAxisLine(true);
	        mChart.getAxisLeft().setDrawGridLines(true);
	        mChart.getAxisRight().setDrawAxisLine(true);
	        mChart.getAxisRight().setDrawGridLines(true);
	        mChart.getXAxis().setDrawAxisLine(false);
	        mChart.getXAxis().setDrawGridLines(false);
	        mChart.getXAxis().setPosition(XAxisPosition.BOTTOM);

	        // enable touch gestures
	        mChart.setTouchEnabled(true);

	        // enable scaling and dragging
	        mChart.setDragEnabled(true);
	        mChart.setScaleEnabled(true);

	        // if disabled, scaling can be done on x- and y-axis separately
	        mChart.setPinchZoom(false);

	        Legend l = mChart.getLegend();
	        l.setForm(LegendForm.CIRCLE);
	        l.setPosition(LegendPosition.BELOW_CHART_CENTER);
	        
	        ArrayList<String> xVals = new ArrayList<String>();//x轴数据
	        for (int i = 0; i <10; i++) {
	            xVals.add((i) + "");
	        }
	 
	        ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>();

	        for (int z = 0; z < 4; z++) {

	            ArrayList<Entry> values = new ArrayList<Entry>();//x轴和y轴交点数据

	            for (int i = 0; i < 10; i++) {
	                double val = Math.random() *10;
	                values.add(new Entry((float) val, i));
	            }

	            LineDataSet d = new LineDataSet(values,classify[z]);//自定义图表提示
	            d.setLineWidth(2.5f);
	            d.setCircleSize(4f);

	            int color = mColors[z % mColors.length];
	            d.setColor(color);
	            d.setCircleColor(color);
	            dataSets.add(d);
	        }
	        // make the first DataSet dashed
//	        dataSets.get(0).enableDashedLine(10, 10, 0);
//	        dataSets.get(0).setColors(ColorTemplate.VORDIPLOM_COLORS);
//	        dataSets.get(0).setCircleColors(ColorTemplate.VORDIPLOM_COLORS);

	        LineData data = new LineData(xVals, dataSets);
	        mChart.animateX(1000);
	        mChart.setData(data);
	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值