In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use android to draw function curves, the article is very detailed, has a certain reference value, interested friends must read it!
/ / layout file / / MainActivity class package com.avi.myapplication5.app;import android.app.Activity;import android.os.Bundle;public class MainActivity extends Activity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main);}} / / DrawActivity class package com.avi.myapplication5.app;import android.content.Context;import android.graphics.Canvas;import android.graphics.Paint;import android.util.AttributeSet Import android.view.MotionEvent;import android.view.View;/** * Created by Administrator on 14-4-18. * / public class DrawActivity extends View implements View.OnTouchListener {float (float) Math.PI of float PI= (float) Math.PI;//PI=3.1415 is too troublesome, customize one. Float canvasWidth,canvasHeight;// canvas width, height float width,height;// Custom length and width float left,up;// Custom position in the upper left corner public DrawActivity (Context context, AttributeSet attrs) {super (context, attrs);} @ Override protected void onDraw (Canvas canvas) {super.onDraw (canvas); / / be sure to call the Init () initialization parameter first. There are no default values for my custom parameters. Init (canvas); Render (canvas);} @ Override public boolean onTouch (View view, MotionEvent event) {return false;} / / initialize global parameters. / / it is recommended not to change the parameters initialized here in other functions, so as not to get the correct result void Init (Canvas canvas) {/ / get canvas width and height canvasWidth= (float) canvas.getWidth (); canvasHeight= (float) canvas.getHeight (); / / Custom length and width width=2*PI;height=2*PI*canvasHeight/canvasWidth / / customize the position of the upper left corner left=-width/2;up=height/2;} / / render the screen. / / the drawing steps are here. Void Render (Canvas canvas) {/ / create a new brush Paint paint=new Paint (); / / draw gridlines. Paint.setARGB (255,255,0,0); DrawGrid (canvas,0.3f,0.3f,paint); / / draw coordinate lines. Paint.setARGB; DrawCoord (canvas,paint); / / displays the names of horizontal and vertical axes and origin. (important note: here is what you want) paint.setARGB (255100100100); DrawCoordName (canvas,paint, "t", "f (t)", "O"); / / draw a curve DrawCurve (canvas,paint);} / draw gridlines. / / draw the grid before the coordinates, otherwise the grid lines will cover the coordinate lines so that you can't see the coordinate lines / / void DrawGrid (Canvas canvas,float dx,float dy,Paint paint) {/ / draw the vertical grid lines / / the left float x lines; while (x > left) {canvas.drawLine (PX (x), PY (up), PX (x), PY (up-height), paint) Xmurf while;} / / on the right side of the box (x)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.