Android effect View fourth bullet line chart heart rate chart

Source: Internet
Author: User

Android effect View fourth bullet line chart heart rate chart


<framelayout        android:layout_width= "match_parent"        android:layout_height= "match_parent" >        < Com.example.empty.ChartView            android:id= "@+id/chart"            android:layout_width= "Wrap_content"            android: layout_height= "Wrap_content"            android:layout_gravity= "center"/>    </FrameLayout>


Package Com.example.empty;import Java.util.arraylist;import Java.util.list;import android.content.context;import Android.graphics.canvas;import Android.graphics.paint;import Android.graphics.point;import Android.util.attributeset;import Android.view.view;public class ChartView extends view{private List mpointlist = new A    Rraylist ();    private int mpointy = 0;   Private Paint Mpoint = new paint ();        Brush public ChartView (context context, AttributeSet attrs) {//TODO auto-generated constructor stub    This (context, attrs, 0); } public ChartView (context context, AttributeSet attrs, int defstyleattr) {Super (context, Attrs, defstyleat        TR);                TODO auto-generated constructor stub//initialization Brush Mpoint.setcolor (GetContext (). Getresources (). GetColor (        R.color.color_tiny_blue));        Mpoint.setstrokewidth (2.0f);    Mpoint.setantialias (TRUE); } @Override protected void OnDraw (Canvas paramcanvas) {Super. OnDraw (Paramcanvas);        Mpointy = (int) (Math.random () * 100); if (Mpointlist.size () >= 2) {for (int k = 0; k <-1 + mpointlist.size (); k++) {Paramcanv As.drawline ((point) mpointlist.get (k)). x, ((point) mpointlist.get (k)). Y, ((            Point) mpointlist.get (k + 1)). x, ((point) mpointlist.get (k + 1)). Y, Mpoint);        }} localPoint1 = new Point (GetWidth (), mpointy);        int i = Mpointlist.size ();        int j = 0;            if (i > 101) {//Draw up to 100 points, redundant out-stack mpointlist.remove (0);                while (J < k) {point localPoint3 = (point) Mpointlist.get (j);                localpoint3.x = ( -7 + localpoint3.x);            j + +;            } mpointlist.add (LOCALPOINT1);        Return } while (J < Mpointlist.size ()) {//each new generation causes each of the preceding points to move left 7 point localPoint2 = (Point) Mpointlist.get (j);            localpoint2.x = ( -7 + localpoint2.x);        j + +;    } mpointlist.add (LOCALPOINT1);    } public final void Clearlist () {mpointlist.clear ();        Public final void addpointtolist (int paramint) {mpointy = Paramint;        Invalidate ();//redraw} public void Stop () {mpointlist.clear ();    Invalidate (); }}

Start Drawing
Mchartview = (ChartView) Findviewbyid (R.id.chart);        Timer timer = new timer ();        TimerTask task = new TimerTask () {            @Override public            void Run () {                message msg = new Message ();                Mhandler.sendmessage (msg);            }        };        Timer.schedule (task,1,300);                            Private Handler Mhandler = new Handler () {        @Override public        void DispatchMessage (Message msg) {            Mchartview.addpointtolist ((int) (Math.random () *));}    ;

above the open line drawing is just to give you a case, the specific effect of everyone according to their own needs to develop. here is a simple explanation of the line chart principle. In fact, here we just take advantage of the principle of the brush line, whenever we receive a new drawing point, we move all the points that existed before, and reconnect them together and draw them back.

Android effect View fourth bullet line chart heart rate chart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.