[Android] Day of development

Source: Internet
Author: User

These days because the computer's USB port has failed, has not played Android-studio

Later, after reloading the computer from Win7-Win10, a portion of the USB port can be used, and then develop Android

Next, follow the book and make a small ball that follows your finger: (I used the Android-studio to upgrade to the latest version 3.0 Beta 1)

Create a new Drawview.java class in the Mainactivity.java directory with the following code:

 Packagecom.oazzz.test7;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Paint;ImportAndroid.util.AttributeSet;Importandroid.view.MotionEvent;ImportAndroid.view.View; Public classDrawviewextendsView { Public floatCurrentX = 40;  Public floatCurrentY = 50; //defining and creating brushesPaint p =NewPaint ();  PublicDrawview (Context context) {Super(context); }     PublicDrawview (context context, AttributeSet set) {Super(context, set); } @Override Public voidOnDraw (canvas canvas) {Super. OnDraw (canvas); //set the color of a brushP.setcolor (color.red); //Draw a small circle (as a ball)Canvas.drawcircle (CurrentX, CurrentY, 15, p); }    //overriding event handling methods for touch events of this component@Override Public Booleanontouchevent (Motionevent event) {//Modify CurrentX, currenty two propertiesCurrentX =Event.getx (); CurrentY=event.gety (); //notifies the current component to redraw itselfinvalidate (); //returns true to indicate that the method has handled the event        return true; }}

Next modify the Mainactivity.java content as:

 Packagecom.oazzz.test7;ImportAndroid.os.Bundle;Importandroid.support.constraint.ConstraintLayout;Importandroid.support.v7.app.AppCompatActivity; Public classMainactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); //get the LinearLayout container in the layout fileConstraintlayout root =(constraintlayout) Findviewbyid (r.id.root); //Creating Drawview Components        FinalDrawview draw =NewDrawview ( This); //set the maximum width and height of a custom componentDraw.setminimumwidth (300); Draw.setminimumheight (500);    Root.addview (Draw); }}

The r.id.root comes from the activity_main.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Android.support.constraint.ConstraintLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:app= "Http://schemas.android.com/apk/res-auto"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Tools:context= "Com.oazzz.test7.MainActivity" android:id= "@+id/root" >    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Hello world!"App:layout_constraintbottom_tobottomof= "Parent"App:layout_constraintleft_toleftof= "Parent"App:layout_constraintright_torightof= "Parent"App:layout_constrainttop_totopof= "Parent" /></Android.support.constraint.ConstraintLayout>

Only the light green part is added.

After reloading the Win10, stepping on a lot of pits, Android-studio is directly from another computer copied over to C:\Program Files\android-studio began to use. You do not need to download the installation JRE or set the environment variables in the system properties. Each time you use Android-studio, Gradle Sync's current configuration is:

[Android] Day of 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.