Andriod drawing and andriod drawing

Source: Internet
Author: User

Andriod drawing and andriod drawing

There are two important components to describe when using view painting:
(1) Paint can be understood as a Paint brush or Paint brush. It is mainly used to set the color, fill mode, transparency, font and Font Style of the drawing.
(2) Canvas. All the images displayed on the view are drawn by canvas. You can draw rectangles, circles, ovans, slices .......

Common Paint methods and attributes:
(1) Paint. Style. FILL the image with color
(2) Paint. Style. FILL_AND_STROKE: draws the border and fills the interior.
(3) Paint. Style. STROKE draw border
(4) paint. setAntiAlias (true), which is used to set the anti-aliasing effect.

I. Design Interface

1. layout File

We use the custom GraphicsView class as the layout and inherit the custom View.
Therefore, you do not need to layout files.

Package com. example. yanlei. wifi; import android. content. context; import android.net. wifi. scanResult; import android.net. wifi. wifiManager; import android. support. v7.app. appCompatActivity; import android. OS. bundle; import android. view. layoutInflater; import android. view. menu; import android. view. menuItem; import android. view. view; import android. view. viewGroup; import android. widget. baseAdapter; import android. widget. imageView; import android. widget. listView; import android. widget. textView; import android. widget. toast; import java. io. file; import java. io. fileNotFoundException; import java. io. fileOutputStream; import java. io. IOException; import javax. xml. parsers. documentBuilder; import javax. xml. parsers. documentBuilderFactory; import javax. xml. parsers. parserConfigurationException; import org. w3c. dom. document; import org. w3c. dom. element; import org. w3c. dom. nodeList; import org. xml. sax. SAXException; import org. xmlpull. v1.XmlPullParser; import org. xmlpull. v1.XmlPullParserException; import org. xmlpull. v1.XmlPullParserFactory; import org. xmlpull. v1.XmlSerializer; import android. app. activity; import android. OS. bundle; import android. util. log; import android. util. xml; import android. view. view; import android. view. view. onClickListener; import android. widget. button; import android. widget. textView; import android. widget. toast; import java. util. list; public class MainActivity extends AppCompatActivity {private static final String BOOKS_PATH = "/sdcard/books. xml "; private View mButton1, mButton2, mButton3; private TextView mTextView; @ Override public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // instantiate GraphicsView graphicsView = new GraphicsView (this); setContentView (graphicsView);} @ Override public boolean values (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. menu_main, menu); return true;} @ Override public boolean onOptionsItemSelected (MenuItem item) {// Handle action bar item clicks here. the action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest. xml. int id = item. getItemId (); // noinspection SimplifiableIfStatement if (id = R. id. action_settings) {return true;} return super. onOptionsItemSelected (item );}}
GraphicsView
Package com. example. yanlei. wifi; import android. content. context; import android. graphics. canvas; import android. graphics. paint; import android. graphics. color; import android. view. view; import android. view. windowManager; public class GraphicsView extends View {// declare Paint paint = null; public GraphicsView (Context context) {super (context ); /* ------------------------------------------ * Paint = new paint () in some books; Put It In The onDraw method. It is recommended that * do not put the initialization brush in the onDraw method as much as possible, because: onDraw often runs * to avoid new objects in it. The fewer the better, otherwise the memory will be wasted * -------------------------------------------- * // get the paint brush and initialize Paint = new (); // onDraw (View) ;}@ Override protected void onDraw (Canvas canvas) {// set the canvas background to a white Canvas. drawColor (Color. WHITE); int width = this. getWidth (); int height = this. getHeight (); paint. setStrokeWidth (4); paint. setColor (Color. YELLOW); canvas. drawRect (0, 0, (float) width-20, (float) height-20, paint); // set the paint brush to red paint. setColor (Color. BLUE); // use the current paint brush to draw a circle canvas with the circle coordinate of 220,100 and the radius of 60. drawCircle (220,180, 60, paint); // set the paint brush to red paint. setColor (Color. RED); // use the current paint brush to draw a rectangular canvas with the coordinates of 80 and 20 in the upper left corner and 360,180 in the lower right corner. drawRect (360,180, paint );}}

Reference: http://blog.csdn.net/jianghuiquan/article/details/8641174

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.