Drawing version of Android development

Source: Internet
Author: User
Tags color representation

drawing version of Android developmentThe New Beginning is also a new challenge:
    • Start to learn Java, in addition to the beginning of some difficult, feel difficult to faint, and slowly contact after the very good, learning 4 days of Android development, completed a small program, the harvest is not small; there are some basic Java, so the relative drawing board is relatively simple (for understanding the code) But because Android and Java have different places, so some places should pay attention to, anyway, fresh things, new starting point. Naughty Cheung にっては.
two. The first knowledge of Android:
  • Android Development, the first impression is that testing trouble, to use a virtual machine or pick up the phone, the first test, very unaccustomed.
  • 2nd: The interface is set on the layout above, Android development like a lot of things are categorized into the same, there are pictures of the package, there is an ID, there is a value package; So, at the beginning, understanding the role of each package is the first step to begin.
  • In Android development, one thing that is not used to is the Android interface, not as in Java is painted in the jframe. The first design is to use a linear layout to set, a vertical linear layout (linearlayout) to add several horizontal linear layouts to be used. Although at the beginning of the time put a lot of mistakes, using the wrong way, not familiar with the development of software, but finally finished.
  • Here's how to control the distance in components and components in layout.
  • different from Java, the way to set colors In Java, color is a class, but Android development uses hexadecimal to indicate, although the system will bring some colors, but to define a new color, you can not like in Java, a color object, but instead: paint.settextcolor ( 0xffff xx ff );//Where: 0XFFFF00FF is the data of type int, group 0x|ff| ff00ff,0x represents the color integer's marker, FF represents transparency, FF00FF represents the color value, note: 0x after the ffff00ff must be a 8-bit color representation. color and non-penetration   (alpha The   value is expressed in hexadecimal notation. The range of values for any one color is  0 to   255 (00 to  FF). for alpha,00 is fully transparent, FF is completely opaque.
  • In addition, Java code is somewhat different;
three. Drawing version:
    • This time to do a drawing version of their own, because it has been written before, so the time spent is not very long, but also easier, but the code is worth noting is still a lot of;
    • The first is that the listener method is different: Java is using the add ..., and Android used in the set...,android Onclicklistener used to monitor the mouse click the equivalent of Java ActionListener, The Ontouchlistener interface is a listening interface for handling mobile screen events that is triggered when a touch is pressed, lifted, or slid within the scope of the view.
    • When you click to enter a new interface, the use of Intent:
  1. Intent is a runtime binding mechanism that connects two different components in the course of a program's operation. With intent, your program can express some kind of request or intention to Android, and Android will choose the appropriate component to respond to the desired content. Intent can be used not only between applications, but also between Activity/service within an application.
  2. Code
            New Intent ();        Intent.setclass (MA, drawactivity. class );        Ma.startactivity (intent);         // the first parameter of the SetClass function is a context                object // context is a class, activity is a subclass of the context class, that               is, // all activity objects can be transformed upward into a context object         // the second parameter of the SetClass function is a class object        , // in the current scenario, you should pass in the class object of the activity class that needs to be started   

    • Use paint brushes when drawing in Android, draw on canvas, save to bitmap bitmap, then place bitmap on Imagineview
    • Second menu:
  1. In the activity function, rewrite the Oncreateoptionsmenu method to create a new menu, and create a new menu file.
  2. Code in the Activity function:
    @Override      Public Boolean Oncreateoptionsmenu (Menu menu) {        getmenuinflater (). Inflate (R.menu.draw, menu);              return true ;    }

  3. Rewrite the activity class's onOptionsItemSelected(MenuItem) callback method, and whenever a menu item is clicked, Android invokes the method and passes in the clicked menu item.
  4. The information obtained by Item.getitemid () is passed into the listener class (the class inherits Ontouchlistener), and the menu function is implemented by the switch statement;
    • When using brushes and canvases, be aware that:
    1. Brush and canvas settings colors can be used in hexadecimal or using the system's own color;
    2. Different functions: In Java, Pip is the way to draw a line, while Android has a special method: Canvas.drawpoint ((x3 + x), (Y3 + y), paint);
    3. The values in the draw function are of type float;
    4. in a function that draws a rectangle void Android.graphics.Canvas.drawRect (float, float top, float right, float bottom, paint paint): Left is the line of the rectangle Top is the top, right is the left, and bottom is the line below.
    5. Pain.setalpha (50);
      Pain.setantialias (TRUE);//change the jagged shape;

    • Motionevent.action_down: Press the
    • MOTIONEVENT.ACTION_UP: Loosen
    • Motionevent.action_move: Mobile
four: Show:

Drawing version of Android development

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.