Statement
Welcome reprint, but please keep the original source of the article →_→
Life One number: http://www.cnblogs.com/smyhvae/
Article Source: http://www.cnblogs.com/smyhvae/p/4392611.html
Series
Everything you should know when using Android studio for the first time
Everything you should know when using Android studio for the first time (ii): Create a new project of your own and install the Genymotion simulator
Everything you should know when using Android studio for the first time (iii): Gradle project Build
Body
All said the holiday does not rest, playing is so capricious!!!
"Development Environment"
Physical Machine Version: Win7 flagship edition (64-bit)
Android Studio Version: 1.1 Official edition
First, the new project:
1. Create a new project:
Open Android Studio and create a new project with the following interface:
, after you have set the project name and path, you can follow it all the way next:
Second, the use of Android studio method;
1. Modify the project structure view:
When project is new, the default structure is as follows:
As you can see, the directory structure of as is very different from eclipse, so let's see the table below for a glance:
Of course, if you want to switch to a similar view in Eclipse, click on the top left corner to switch views:
After switching, the view is as follows:
, the app at the arrow is actually a module, and the concept of module is explained later.
2, the common functions of the toolbar:
There are several commonly used buttons on the as toolbar, namely Gradle Sync, AVD Manager, SDK Manager, DDMS, as shown in:
The explanations are as follows:
- Gradle synchronization: When you run the project or change the Gradle configuration, you have to click this button, will download the corresponding dependency
- AVD Manager: Emulator Manager
- SDK Manager: Just manage your SDK version
- DDMS: Dalvik Debug Monitor Service,dalvik Debug monitoring service.
3. Import third-party jar packages:
The import jar package in Eclipse is the first to copy the jar package into the project file and then add to build path, but not in Android studio. The way to import a jar package in Android Studio is: (take Google's Gjson.jar as an example)
Copy the Gson-2.3.jar file to the Libs directory of the project file:
After importing, select the Jar package and click the button at the Middle arrow: (Synchronize: Sync, can be understood as refresh)
Get.
Third, install the Genymotion simulator:
1, the installation of genymotion:
Genymotion is undoubtedly the fastest and best simulator available. Official website: https://www.genymotion.com/
The simplest way to register, then download, and install VirtualBox is to download a genymotion package that contains VirtualBox, as shown in the Red box section:
When the download is complete, start the installation. Then run the Genymotion software, you will be prompted to create a virtual device, click the Yes button to start creating a virtual device:
Connect using a previously registered account:
Then select one of the versions of the emulator:
Of course, if you want to run the program on the emulator, make sure the emulator is loaded with the Android SDK:
Note: If the following error occurs when you start the emulator:
Upgrade your computer graphics card driver on the line.
In this way, our simulator is built and can be started up. Next, you'll associate the emulator with Android studio.
2. Associate Simulator Genymotion with Android Studio:
Genymotion Official website Tip There are two methods (as shown), one for online installation and the other for offline installation. The method is already very clear, I will not screen the demo ha.
After the plugin is installed, reboot the software and let the newly loaded plugin take effect. After restarting the software Android Studio, select the menu bar "View--toolbar" and let the toolbar appear, and you can see that the toolbar has a Genymotion Device Manager icon:
Click on this icon to bring up the following screen:
, load our previously installed Genymotion folder. Then click on this icon to bring up the following screen:
Done.
Next, run the program on the emulator:
The results are as follows:
, you can see that the version I compiled is API 19, but the emulator version is API 16, but the program is still running, which shows that Android studio does a good job with version compatibility issues. However, prior to using IntelliJ idea, you must require that the compiled version and the emulator (real machine) version be consistent.
Iv. creating a third-party library in module form: (Introduction of module concept)
Look at this table again:
After reading the picture, you should know the concept of module. The attentive little companion can find that the application module has a mobile icon:
1, a new module as the library: (take stickyscrollviewitems This library as an example )
Note: The effect ofStickyscrollviewitems is that the child control can hover over the ScrollView (fixed at the top when the child controls scroll to the top of the page).
In the AS, we can create a new module to use as the library, operating as follows:
, create a new module in the current project, and then pop up the following interface:
, select the type of module for the Android Library, and then continue:
, since this module is a libray, there is no need for activity.
The two module at the Middle Arrow: the first is the application module, the second is the Lirary module, and you can see that their icon icons look different.
2. Copy some of the files from the Stickyscrollviewitems-master compressed package on GitHub to the Lirary module:
The operation is as follows:
(1) The stickyscrollviewitems-master\stickyscrollviewitems-master\library\res\ The Attrs.xml file in the values directory is copied to the values directory in the Lirary module.
(2) The Stickyscrollviewitems-master\stickyscrollviewitems-master\library\src\com\emilsjolander\components\ The Stickyscrollview.java file in the Stickyscrollviewitems directory is copied to the Java directory in the Lirary module.
The final effect is as follows:
Summary: a common practice for creating a third-party library in module form is to:
(1) Create a new module in the library form and delete all the files in the src/main directory in this module (including deleting Java, res, androidmanifest.xml)
(2) Copy the Androidmainfest.xml, res, src files (clips) from the third-party library to the Src/main directory of the Library directory
(3) Rename the src directory under the Src/main directory (SHIFT+F6) to Java
(4) Remove the dependencies and release modules from the Build.gradle file in the Library module (be careful not to modify the wrong place)
3, the application module depends on the library module:
The operation is as follows:
, right-click on the app and select "Open Module Settings" to bring up the following interface:
Follow the steps, in the Dependencies tab, add "Module dependency", pop up the following interface:
, you can import the Stickyscrollviewitems module.
Depends on success, so we can see its code hints in the layout file:
Let's test it here.
4. Test the usability of the Library module:
Modify the Activity_main.xml to the following code:
1 <com.smyhvae.stickyscrollview.stickyscrollview 2 android:layout_width= "Match_parent" 3 android:layout_height= "Match_parent" 4 android:fadingedge= "none" 5 android:overscrollmode= "never" 6 android:fillviewport= "true" 7 Xmlns:android= "Http://schemas.android.com/apk/res/android" > 8 9 <linearlayout10 android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:orientation= "vertical" >13 T VIEW15 android:layout_width= "match_parent" android:layout_height= "200DP" android:b ackground= "@color/blue"/>18 <view20 android:layout_width= "Match_parent" Android : layout_height= "100DP" android:background= "@color/red"android:tag= "sticky"/><view26 android:layout_width= "match_parent" android:layout_height= "100DP" 28 android:background= "@color/green"/>29 <view30 android:layout_width= "Match_parent" 31 android:layout_height= "100DP" android:background= "@color/white"/>33 <view35 Android:layout_width= "Match_parent" android:layout_height= "300DP" Notoginseng android:background= "@c Olor/purple "/>38" <view40 android:layout_width= "Match_parent" Android:layout_hei ght= "100DP" android:background= "@color/yellow"/>43 </linearlayout>45 </com.smyhvae.sticky ScrollView. Stickyscrollview>
In the above code, we introduced the module Stickyscrollview as the library, the core code is the 23rd line, we added the red view android:tag= "sticky" this tag, so it will have hover properties. Then run the program directly.
The entire project file for this section is as follows: (You can import into your own as to run a look at the effect)
Links: Http://pan.baidu.com/s/1eQ8epsY
Password: k9i1
V. Delete a module:
, what should I do if I want to delete the module Stickyscrollview? The way is: Select Stickyscrollview this module, and right click, found no delete option, no relationship, we select the Red box section of the "Open module Settings" option, pop up the following interface:
, click the minus sign at the arrow to delete it. At the same time we want to remove the app this module relies on it:
You will then notice that the icon for the module Stickyscrollview disappears:
, and now right-click it, you can delete it and delete it from the hard disk directly:
Vi. tips for deleting files: (Safe removal)
If we want to delete a file, we can right-click and delete, but Android studio has a more user-friendly experience. For example, when I want to delete a layout file:
, click Delete to remove it, and the following screen appears:
, if the red box part is ticked, then click OK, the software will prompt you, where to use this file:
Show that there is a place to use this file, click on the "View usages", you can see the detailed situation:
If you are determined to delete, click the arrow position can be, how? Is the user experience good?
How? Still not satisfied? I will continue to fight tomorrow, so please wait ~ ~ ~
Note:
In my fourth paragraph, a new module was used as the library, and the library was quoted in Stickyscrollviewitems. The entire project file is also given a download link at the end of the fourth paragraph, where the Gradle file code is as follows: (Gradle will be covered in the next article)
Application's Build.gradle:
1//top-level build file where can add configuration options common to all sub-projects/modules. 2 3 Buildscript {4 repositories {5 jcenter () 6 } 7 Dependencies {8 classpath ' com.android.tools.build:gradle:1.1.0 ' 9 //Note:do not place your application dependencies here; they belong11
//in the individual module Build.gradle files12}13}14 all allprojects {repositories {jcenter () 18
}19}
App's Build.gradle:
1 Apply plugin: ' Com.android.application ' 2 3 Android {4 compilesdkversion 5 buildtoolsversion "21.1.1" 6 7 defaultconfig {8 ApplicationID "Com.smyhvae.helloworld" 9 minsdkversion 1410 Targetsdkversion 1911 Versioncode versionname "1.0"}14 buildtypes { release {16 minifyenabled false17 proguardfiles getdefaultproguardfile (' proguard-android.txt '), ' Proguard-rules.pro ' }19 }20}21, dependencies {compile Filetree (dir: ' Libs ', include: [' *.jar ']) Compile Project (': Stickyscrollview ') 25}
Library This module's build.gradle:
1 Apply plugin: ' Com.android.library ' 2 3 Android {4 compilesdkversion 5 buildtoolsversion "21.1.1" 6
7 defaultconfig {8 minsdkversion 9 targetsdkversion 1910 Versioncode 111 Versionname "1.0" 12 }13 buildtypes { release { minifyenabled false16 proguardfiles getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro ' }18 }19}20, dependencies {compile Filetree (dir : ' Libs ', include: [' *.jar ']) 23}
Everything you should know when using Android studio for the first time (ii): Create a new project of your own and install the Genymotion simulator