欧美三级国产三级日韩三级_亚洲熟妇丰满大屁股熟妇_欧美亚洲成人一区二区三区_国产精品久久久久久模特

基于Android的計(jì)步器(Pedometer)的講解(二)——柱狀圖 - 新聞資訊 - 云南小程序開(kāi)發(fā)|云南軟件開(kāi)發(fā)|云南網(wǎng)站建設(shè)-昆明葵宇信息科技有限公司

159-8711-8523

云南網(wǎng)建設(shè)/小程序開(kāi)發(fā)/軟件開(kāi)發(fā)

知識(shí)

不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價(jià)值,我們?cè)谧非笃湟曈X(jué)表現(xiàn)的同時(shí),更側(cè)重于功能的便捷,營(yíng)銷(xiāo)的便利,運(yùn)營(yíng)的高效,讓網(wǎng)站成為營(yíng)銷(xiāo)工具,讓軟件能切實(shí)提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序?yàn)楹笃谏?jí)提供便捷的支持!

您當(dāng)前位置>首頁(yè) » 新聞資訊 » 技術(shù)分享 >

基于Android的計(jì)步器(Pedometer)的講解(二)——柱狀圖

發(fā)表時(shí)間:2020-10-19

發(fā)布人:葵宇科技

瀏覽次數(shù):42


寫(xiě)正文之前,小小的吐槽一下,還有一個(gè)月就放假了,功課、測(cè)驗(yàn)、還有練習(xí)(研一,下半學(xué)期課不多,也不想在實(shí)驗(yàn)室)的┞峰酌,比來(lái)基于hadoop的數(shù)據(jù)分析立時(shí)也要驗(yàn)收了,真的忙的“外焦里嫩”啊!今朝定的偏向是Android開(kāi)辟,所以想過(guò)年來(lái)了找一個(gè)Android的練習(xí)工作,進(jìn)步一點(diǎn)在真正的項(xiàng)目中的經(jīng)驗(yàn)。
好了,說(shuō)了這么多廢話,開(kāi)端進(jìn)入正題吧。
全部計(jì)步器的項(xiàng)目已經(jīng)上傳到github上了,感興趣的同伙可以去看看(最好能給小弟我打倒星星哦~)
https://github.com/296777513/pedometer
項(xiàng)目整體介紹前面介紹過(guò):http://blog.csdn.net/a296777513/article/details/42339693
起首,這是兩張今天要實(shí)現(xiàn)的效不雅圖:
(固然這個(gè)可以用沒(méi)問(wèn)題,我在另一篇的博文里已經(jīng)進(jìn)行優(yōu)化了,界面加倍好看
http://blog.csdn.net/a296777513/article/details/42386769) 
[img]http://img.blog.csdn.net/20150103185924361?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTI5Njc3NzUxMw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center[img]http://img.blog.csdn.net/20150103190012484?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYTI5Njc3NzUxMw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
最重要的實(shí)現(xiàn)本身寫(xiě)的一個(gè)HistogramView的類(lèi)(柱狀圖類(lèi))
HistogramView的代碼如下:

package com.example.histogram.widet;



import com.example.changepage1.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;


/**
 * 這是從新寫(xiě)的一個(gè)柱狀圖的view
 * Author: 李埡超   email:[email protected]
 * Date: 2015-1-3
 * Time: 下晝6:15
 */
public class HistogramView extends View {
	private boolean Text = false;//斷定是否在柱狀圖上顯示數(shù)字
	private int Height;//控件高度
	private int Width;//控件寬度
	private Bitmap bitmap;//柱狀圖的樣子
	private int mHeight;//柱狀圖高度
	private int AnimValue;//實(shí)現(xiàn)的動(dòng)畫(huà)
	private double Progress;

	private Canvas canvas;//畫(huà)出柱狀圖的各個(gè)屬性
	private HistogramAnimation ani;

	public void setText(boolean mText) {
		this.Text = mText;
		invalidate();

	}

	public HistogramView(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		ani = new HistogramAnimation();//初始化自定義的動(dòng)畫(huà)類(lèi)
		ani.setDuration(1000);//設(shè)置全部動(dòng)畫(huà)在1秒內(nèi)完成
	}

	public HistogramView(Context context, AttributeSet attrs) {
		super(context, attrs);
		ani = new HistogramAnimation();
		ani.setDuration(1000);
	}

	@Override
	protected void onSizeChanged(int w, int h, int oldw, int oldh) {
		super.onSizeChanged(w, h, oldw, oldh);
		//初始化控件和進(jìn)度的條相干參數(shù)
		Width = w;
		Height = h;
		mHeight = (int) (h * Progress * 0.9);

	}

	@SuppressLint("DrawAllocation")
	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		this.canvas = canvas;
		
		Paint paint = new Paint();//設(shè)置矩形畫(huà)筆,設(shè)置柱狀圖的信息
		paint.setAntiAlias(true);
		paint.setStyle(Paint.Style.FILL);
		paint.setTextSize(sp2px(getContext(),12));
		paint.setColor(Color.parseColor("#6DCAEC"));


		// 繪制 柱狀圖的外形 :left,top,right,bottom
		RectF dst = new RectF(0, Height - AnimValue, Width, Height);
		//掏出圖片,并且轉(zhuǎn)換為bitmap類(lèi)型
		bitmap = BitmapFactory
				.decodeResource(getResources(), R.drawable.column);

		this.canvas.drawBitmap(bitmap, null, dst, paint);//畫(huà)出柱狀圖
		if (Text) {
			if (Progress != 0) {
				this.canvas.drawText((int) (Progress * 10000) + "", 0,
						(Height - AnimValue) - 10, paint);
			} else {
				this.canvas.drawText((int) (Progress * 10000) + "", 0,
						(Height - AnimValue) - 10, paint);
			}

		}
	}

	/**
	 * 對(duì)外供給接口來(lái)傳進(jìn)數(shù)值
	 * @param Progress
	 */
	public void setProgress(double Progress) {
		if (Progress < 0.03 && Progress != 0) {
			this.Progress = Progress;
			Progress = 0.03;
		}
		this.Progress = Progress;
		this.startAnimation(ani);
	}

	/**
	 * 集成animation的一個(gè)動(dòng)畫(huà)類(lèi)
	 * @author 李埡超
	 *
	 */
	private class HistogramAnimation extends Animation {
		@Override
		protected void applyTransformation(float interpolatedTime,
				Transformation t) {
			super.applyTransformation(interpolatedTime, t);
			if (interpolatedTime < 1.0f) {
				AnimValue = http://www.sjsjw.com/100/000345MYM003870/(int) (mHeight * interpolatedTime);
			} else {
				AnimValue = mHeight;
			}
			postInvalidate();
		}
	}
	

    public static int sp2px(Context context, float spValue) { 
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity; 
        return (int) (spValue * fontScale + 0.5f); 
    } 

}

重寫(xiě)FragmentAnalysis類(lèi)

package com.example.histogram;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import com.example.changepage1.R;
import com.example.histogram.widet.HistogramView;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.annotation.SuppressLint;

import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Transformation;

import android.widget.TextView;

/**
 * 這是分析七天步數(shù)的碎片 Author: 李埡超 email:[email protected] Date: 2015-1-2 Time: 下晝2:39
 */
public class FragmentAnalysis extends Fragment implements OnClickListener {
	private HistogramView hv1, hv2, hv3, hv4, hv5, hv6, hv7;// 這是7個(gè)條形柱狀圖

	private TextView day1, day2, day3, day4, day5, day6, day7;// 這是底部顯示的一周7天

	private TextView average_step;// 平均步數(shù)
	private TextView sum_step;// 總共步數(shù)

	private int average = 0;
	private int sum = 0;
	private int average1 = 0;
	private int sum1 = 0;

	private Calendar calendar;// 日期的操作
	private String day;

	private View view;

	private AllAnimation ani;// 設(shè)置的動(dòng)畫(huà)

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		view = inflater.inflate(R.layout.analysis, container, false);
		return view;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		init();
		setWeek();
		setProgress();
		view.startAnimation(ani);

	}

	/**
	 * 初始化一些對(duì)象
	 */
	private void init() {
		average_step = (TextView) view.findViewById(R.id.average_step);
		sum_step = (TextView) view.findViewById(R.id.sum_step);
		ani = new AllAnimation();// 創(chuàng)建自定義的動(dòng)畫(huà)對(duì)象
		ani.setDuration(1000);// 設(shè)置完成動(dòng)畫(huà)的時(shí)光為1秒

		calendar = Calendar.getInstance();// 對(duì)日期進(jìn)行實(shí)例化,顯示當(dāng)天的日期

		hv1 = (HistogramView) view.findViewById(R.id.map1);
		hv2 = (HistogramView) view.findViewById(R.id.map2);
		hv3 = (HistogramView) view.findViewById(R.id.map3);
		hv4 = (HistogramView) view.findViewById(R.id.map4);
		hv5 = (HistogramView) view.findViewById(R.id.map5);
		hv6 = (HistogramView) view.findViewById(R.id.map6);
		hv7 = (HistogramView) view.findViewById(R.id.map7);

		// 對(duì)7個(gè)柱狀圖設(shè)置點(diǎn)擊時(shí)光,可以顯示具體的數(shù)值
		hv1.setOnClickListener(this);
		hv2.setOnClickListener(this);
		hv3.setOnClickListener(this);
		hv4.setOnClickListener(this);
		hv5.setOnClickListener(this);
		hv6.setOnClickListener(this);
		hv7.setOnClickListener(this);

		// 顯示對(duì)應(yīng)的周數(shù)
		day1 = (TextView) view.findViewById(R.id.Monday);
		day2 = (TextView) view.findViewById(R.id.Tuesday);
		day3 = (TextView) view.findViewById(R.id.Wednesday);
		day4 = (TextView) view.findViewById(R.id.Thursday);
		day5 = (TextView) view.findViewById(R.id.Friday);
		day6 = (TextView) view.findViewById(R.id.Saturday);
		day7 = (TextView) view.findViewById(R.id.Sunday);

	}

	@SuppressLint("SimpleDateFormat")
	private void setProgress() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		day = sdf.format(calendar.getTime());
		// Toast.makeText(getActivity(), day + "", Toast.LENGTH_LONG).show();
		hv1.setProgress((5000 / 10000.0));
		sum += 5000;

		calendar.add(Calendar.DAY_OF_MONTH, -1);//把日期設(shè)置成為
		day = sdf.format(calendar.getTime());
		hv2.setProgress((3000 / 10000.0));
		sum += 3000;
		// Toast.makeText(getActivity(), day+"", Toast.LENGTH_LONG).show();

		calendar.add(Calendar.DAY_OF_MONTH, -1);
		day = sdf.format(calendar.getTime());
		hv3.setProgress((2000 / 10000.0));
		sum += 2000;

		calendar.add(Calendar.DAY_OF_MONTH, -1);
		day = sdf.format(calendar.getTime());
		hv4.setProgress((7631 / 10000.0));
		sum += 7631;

		calendar.add(Calendar.DAY_OF_MONTH, -1);
		day = sdf.format(calendar.getTime());
		hv5.setProgress((4213 / 10000.0));
		sum += 4213;

		calendar.add(Calendar.DAY_OF_MONTH, -1);
		day = sdf.format(calendar.getTime());
		hv6.setProgress((8431/ 10000.0));
		sum += 8431;

		calendar.add(Calendar.DAY_OF_MONTH, -1);
		day = sdf.format(calendar.getTime());
		hv7.setProgress((9999 / 10000.0));
		sum += 9999;

	}

	/**
	 * 設(shè)置禮拜
	 */
	private void setWeek() {

		int day = calendar.get(Calendar.DAY_OF_WEEK);//當(dāng)天的周數(shù)
		// Toast.makeText(getActivity(), day + "", Toast.LENGTH_LONG).show();
		day -= 1;
		day1.setText(week(day));
		day2.setText(week(day - 1));
		day3.setText(week(day - 2));
		day4.setText(week(day - 3));
		day5.setText(week(day - 4));
		day6.setText(week(day - 5));
		day7.setText(week(day - 6));
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.map1:
			hv1.setText(true);
			hv2.setText(false);
			hv3.setText(false);
			hv4.setText(false);
			hv5.setText(false);
			hv6.setText(false);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map2:
			hv1.setText(false);
			hv2.setText(true);
			hv3.setText(false);
			hv4.setText(false);
			hv5.setText(false);
			hv6.setText(false);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map3:
			hv1.setText(false);
			hv2.setText(false);
			hv3.setText(true);
			hv4.setText(false);
			hv5.setText(false);
			hv6.setText(false);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map4:
			hv1.setText(false);
			hv2.setText(false);
			hv3.setText(false);
			hv4.setText(true);
			hv5.setText(false);
			hv6.setText(false);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map5:
			hv1.setText(false);
			hv2.setText(false);
			hv3.setText(false);
			hv4.setText(false);
			hv5.setText(true);
			hv6.setText(false);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map6:
			hv1.setText(false);
			hv2.setText(false);
			hv3.setText(false);
			hv4.setText(false);
			hv5.setText(false);
			hv6.setText(true);
			hv7.setText(false);
			view.invalidate();
			break;
		case R.id.map7:
			hv1.setText(false);
			hv2.setText(false);
			hv3.setText(false);
			hv4.setText(false);
			hv5.setText(false);
			hv6.setText(false);
			hv7.setText(true);
			view.invalidate();
			break;

		default:
			break;
		}

	}

	/**
	 * 將禮拜由阿拉伯?dāng)?shù)字變?yōu)闈h字
	 * @param day
	 * @return
	 */
	private String week(int day) {
		if (day < 1) {
			day += 7;
		}
		switch (day) {
		case 1:
			return "周一";
		case 2:
			return "周二";
		case 3:
			return "周三";
		case 4:
			return "周四";
		case 5:
			return "周五";
		case 6:
			return "周六";
		case 7:
			return "周日";
		default:
			return "";
		}
	}

	/**
	 * 自定義的一個(gè)動(dòng)畫(huà)類(lèi)
	 * @author 李埡超
	 *
	 */
	private class AllAnimation extends Animation {
		@Override
		protected void applyTransformation(float interpolatedTime,
				Transformation t) {
			super.applyTransformation(interpolatedTime, t);
			if (interpolatedTime < 1.0f) {
				sum1 = (int) (sum * interpolatedTime);
				average1 = (int) (average * interpolatedTime);
			} else {
				sum1 = sum;
				average1 = average;
			}
			view.postInvalidate();
			sum_step.setText(sum1 + "");
			average = sum / 7;
			average_step.setText(average1 + "");

		}
	}

}
       
FragmentAnalysis對(duì)應(yīng)的xml頁(yè)面代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="left"
            android:layout_marginLeft="10dp"
            android:contentDescription="@string/app_name" />

        <TextView
            android:id="@+id/analysis"
            android:layout_width="0dp"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/analysis"
            android:textColor="#6DCAEC"
            android:textSize="20sp" />

        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="left"
            android:layout_marginLeft="10dp"
            android:contentDescription="@string/app_name" />
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/sumstep"
            android:textSize="20sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/averagestep"
            android:textSize="20sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/sum_step"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/_0"
            android:textColor="#6DCAEC"
            android:textSize="30sp"
            android:typeface="normal" />

        <TextView
            android:id="@+id/average_step"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="@string/_0"
            android:textColor="#6DCAEC"
            android:textSize="30sp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="10"
        android:orientation="horizontal" >

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map1"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="40dp"
            android:layout_marginTop="30dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map2"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map3"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map4"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map5"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map6"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />

        <com.example.histogram.widet.HistogramView
            android:id="@+id/map7"
            android:layout_width="30dp"
            android:layout_height="250dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="5dp" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:text="@string/_0k"
            android:textSize="15sp" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="40dp"
            android:background="@android:color/darker_gray" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:layout_marginTop="5dp"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/Monday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:text="@string/Monday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Tuesday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Tuesday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Wednesday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Wednesday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Thursday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Thursday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Friday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Friday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Saturday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Saturday"
            android:textSize="15sp" />

        <TextView
            android:id="@+id/Sunday"
            android:layout_width="30dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:text="@string/Sunday"
            android:textSize="15sp" />
    </LinearLayout>

</LinearLayout>


相關(guān)案例查看更多