Android Learning Diary 1 - FirstProject

emmmm fact, this blog should be written yesterday, but because someone was too lazy, so I had to drag today.

After learning Java for some time, I am simply rely on the memory of knowledge do not fly, you must learn in practice. So I started to learn Android development. Android is very clear purpose of learning, one participating country to create (or other type of game), the second is to do in this game before participating in an App (currently there are two envisioned, one family bucket Western Electric, the second is personal schedule management) the third is the accumulation of the project experience.

Here I would like to briefly imagine family bucket of Western Electric. Since the Super curriculum is too slow, and as a last resort to commercial software add a lot of advertising, so that we look at the curriculum costly (in time), but also added a lot less than we function very Zaoxin. So I imagine doing a really belong App West, students, and through which you can check the class schedule, grades, traffic, water and electricity and so on. Since I currently just beginning to learn, so I do not know what will meet resistance, but it is certain that, I need to learn Android development (this nonsense), and server and database management, of course, I intend to make a beta version after invite more to do with the students.

The previous statement, learning books used as the first line of code (Android) Guo Lin prepared a second edition, Java Java to learn the knowledge auditorium for the B station with data entry (av76235341)

All the contents of the previous life, perception of what the article are learning, beginners will inevitably loose place, if you are white does not care to see the article, emmmm look like, if you are a big brother smiled emmmmm like, look to your wing

File Directory

Learn the necessary environment to build and create in this project will not go, first of all talk about the project directory created.

After the project is created Android Studio will automatically help you generate a lot of documents, most of which you do not need to change or concern.

Android Studio offers at least two file view modes (I only used two kinds), one is Project, one is Android, respectively, as shown:

 

 

 The left side is a real project directory structure, converted to the right of Android Studio directory structure for rapid development.

Left side view an example to explain

Project

Of course, so many documents, I do not know what, because I have not used, now I know what it is:

  1. .gradle and .idea: Android Studio automatically generated files, do not care about, do not edit
  2. app: project code, resource storage directory, is our main development directory
  3. build: no need relationship, some of the files are automatically generated when the project is compiled
  4. ActivistyTest.iml: This is used to represent a IntelliJ IDEA project, without having to modify (there is one that really a IntelliJ NB)

app

Other I do not really understand, the following detail about the content inside the app as:

 

 

 

 

 

 

  1. build: build directory and outer layers similar, but also some of the compiled file, but more complex, without concern
  2. libs: third-party jar package (I do not know is what, I understood that to be third-party libraries and language almost)
  3. src: emmmm project files are stored, the open see it:

src

 

  1. java: local storage of Java code, written in the code stored here
  2. androidTest: Android Test writing test cases (I do not know what is), can be automated testing project
  3. test: Another way of automated testing, Unit Test Test
  4. AndroidManifest.xml: Android project profile, similar to the registry (I was so understandable, so after learning more, come and supplementary)
  5. res: all the pictures (drawable), layout (layout), string (values), icons (mipmap) are placed here (brackets not in English, but they are stored in a subdirectory), as shown:
res

 

 

 Specific documents

Android pay attention to the separation of logic and view, write logic in Java files, stored in the resource res view, you can refer to these resources in activities referenced in the syntax is:

R.string.name code 
@string / xml file name in the

For example, it is a simple application interface only the words: "Hello World", its Java files as follows:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

MainActivity class inherits AppCompatActivity, Activity is a base class Android system provides, AppCompatActivity is one of its subclasses, on behalf of this is a compatible activities. All activities in the project must be characteristic of it or its subclasses can have activities .

Here rewrite a method: onCreate, this method is called automatically when an activity is to create a second line of this method calls setContentView method, introduced a layout activity for the current activity, we find this layout in res / layout directory file, open the following:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:app="http://schemas.android.com/apk/res-auto"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context=".MainActivity">
 8 
 9     <TextView
10         android:layout_width="wrap_content"
11         android:layout_height="wrap_content"
12         android:text="Hello World!"
13         app:layout_constraintBottom_toBottomOf="parent"
14         app:layout_constraintLeft_toLeftOf="parent"
15         app:layout_constraintRight_toRightOf="parent"
16         app:layout_constraintTop_toTopOf="parent" />
17 
18 </androidx.constraintlayout.widget.ConstraintLayout>

In 12 lines define a text as "Hello World!", App of the character display is this one, the other I am not clear, but "wrap_content" means just wrap.

AndroidManifest.xml

Open this file:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.example.helloworld">
 4 
 5     <application
 6         android:allowBackup="true"
 7         android:icon="@mipmap/ic_launcher"
 8         android:label="@string/app_name"
 9         android:roundIcon="@mipmap/ic_launcher_round"
10         android:supportsRtl="true"
11         android:theme="@style/AppTheme">
12         <activity android:name=".MainActivity">
13             <intent-filter>
14                 <action android:name="android.intent.action.MAIN" />
15 
16                 <category android:name="android.intent.category.LAUNCHER" />
17             </intent-filter>
18         </activity>
19     </application>
20 
21 </manifest>

See lines 5 to 19

icon for the application icon in this project, you can see a reference to the mipmap inside ic_launcher files, label the name of the application, citing the string inside the file app_name

Noting lines 12 to 19, where the activity of MainActivity register, which has a sub-tag <intent-filter>, inside the two lines indicates that this is a main activity, i.e., the open event is to run App.

Log

Finally, to tell you the Log method (logging tool), from low level to high level as follows:

  • Log.v (), verbose level, print trivial, meaning a minimum of log information
  • Log.d (), debug level, print helpful information for debugging and analyzing problems
  • Log.i (), info level, print more important information, some of you want to see, it can be used to help analyze user behavior data
  • Risk Log.w (), warn levels, print a warning message stating that the program's potential
  • Log.e (), error level, the program prints an error message, the general procedure for serious problems, it should be repaired as soon as possible

Usage is as follows:

Log.d("MainActivity", "onCreate: execute");

This method has two parameters, tag and msg, labeling and information, which content on grammar should not be defined, in the practical application of a general fill in the current class name, the second is what you want to print , if the statement is executed as follows:

 

 Convenient, what time are printed out, would not Yoshiya? What System.out.println ()

And the input In Android Studio logt, press the Tab key automatically help you set up a constant:

 

Constant is the current class name, got it, quickly use it!

(Yu know what filters do not say, explore it on their own)

Guess you like

Origin www.cnblogs.com/RainCurtain/p/12213665.html