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
Contact information: [Email protected]
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:
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:
Eclipse
Ieda/android Studio
Work area
Workspace
Project
Project
Project
Module
Reference
Preference
Module dependency
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:
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.StickyScrollView2 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 <LinearLayoutTen Android:layout_width= "Match_parent" One Android:layout_height= "Wrap_content" A android:orientation= "vertical"> - - <View the Android:layout_width= "Match_parent" - Android:layout_height= "200DP" - Android:background= "@color/blue"/> - + <View - Android:layout_width= "Match_parent" + Android:layout_height= "100DP" A Android:background= "@color/red" android:tag= "sticky"/> - - <View - Android:layout_width= "Match_parent" - Android:layout_height= "100DP" - Android:background= "@color/green"/> in <View - Android:layout_width= "Match_parent" to Android:layout_height= "100DP" + Android:background= "@color/white"/> - the <View * Android:layout_width= "Match_parent" $ Android:layout_height= "300DP"Panax Notoginseng Android:background= "@color/purple"/> - the <View + Android:layout_width= "Match_parent" A Android:layout_height= "100DP" the Android:background= "@color/yellow"/> + - </LinearLayout> $ </Com.smyhvae.stickyscrollview.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.
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 ~ ~ ~
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