Android Studio you may be ignoring the details--start white screen? What is the meaning of drawable and mipmap? There are all here!!!

Source: Internet
Author: User

Android Studio for a long time, do not know if you have a small partner is still in use eclipse, if there is, the landlord really recommended to go to Android studio, after all, pro-son, you will know that in addition to the start speed slightly slower, You can't find a place to Renmin Eclipse, oh, your computer is not too bad

1) First of all, let's say that Android studio launches the app black-and-white screen.

The studio was recently upgraded to 2.1.1 and a problem was found. In the start of a new project, the app will always appear a long time white screen or black screen, the landlord has always thought is the landlord to connect the company project algorithm too time-consuming reason, but the landlord in writing small demo when unexpectedly also found such problems, and this situation in the Internet is quite frequent, The landlord will go online to see the problem, please see, the image from the network.

Look around, just know this is the new features of Android Studio launch, Instant Run, well, for this thing, Lou Zhu do not want to do too much in-depth explanation, well, you found, is the landlord afraid that they do not speak this thing.

And this thing has been criticized by the vast number of friends, but the landlord carefully see a little new things, the original in the restart when you can directly restart activity, instead of starting the entire app, so that directly speed up our development efficiency has wood?

As you can see, there is a lightning bolt on the left side of this run, which means that it can be started with insant run.

Well, in addition to everyone's concern, say, this thing is only Google official in 2.0 in order to speed up our development efficiency and do, in fact, you really use the app when you do not appear this may be up to 7, 8 seconds of black and white screen situation, but also hope not to know the small partner pressure yajing.

2) Again, the choice of Android studio Mipmap and drawable.

As we all know, Android studio compared to eclipse, in the resource package res, a folder Mipmap, inside the sub-folder unexpectedly and drawable under the same, that flat more to do what?

View official documents, the following information from Google official.

Well, I believe that the English level of the small partners will not be more than the landlord of the Slag bar, the landlord simply looked at a bit, probably mean:

The drawable package can store png,jpeg,gif image files, as well as the ones we develop frequently. 9 figure, but the drawable package is mainly to store some custom graphics and buttons such as color change XML.

And Mipmap is purely for the storage application icon and some other pictures, which is also the official strongly recommended that we use mipmap storage images, the official said the picture under the mipmaps can improve the speed of the system rendering pictures, improve picture quality, reduce GPU pressure.

3) Well, in fact, the landlord most want to say is still mipmap the role of several packages and screen adaptation of the partial processing.

First, the landlord in the Landlord's blog home page simply cut a picture, placed under the Xhdpi folder under the Mipmap.

Because the landlord's mobile phone is xhdpi density, for viewing their cell phone density, can be processed by two lines of code.

1  Public void Btnclick (view view) {2         float xdpi = getresources (). Getdisplaymetrics (). xdpi; 3         float ydpi = getresources (). Getdisplaymetrics (). ydpi; 4         TextView TextView = (TextView) Findviewbyid (r.id.text); 5         Textview.settext ("width:" +xdpi+ "    Height:" +ydpi); 6     }

The landlord's XML file is very simple.

1<?xml version= "1.0" encoding= "Utf-8"?>2<LinearLayout3Xmlns:android= "Http://schemas.android.com/apk/res/android"4Xmlns:tools= "Http://schemas.android.com/tools"5Android:layout_width= "Match_parent"6android:layout_height= "Match_parent"7android:orientation= "Vertical"8tools:context= "Com.example.nanchen.drawablemipmapdemo.MainActivity" >9 Ten<Button OneAndroid:layout_width= "Match_parent" Aandroid:layout_height= "Wrap_content" -android:text= "Get screen width" -android:onclick= "Btnclick"/> the<TextView -Android:layout_width= "Match_parent" -android:layout_height= "Wrap_content" -Android:id= "@+id/text" +android:text= "For display screen width height"/> -  +<TextView Aandroid:layout_margintop= "10DP" atAndroid:layout_marginbottom= "10DP" -Android:layout_width= "Match_parent" -android:layout_height= "1DP" -android:background= "#9c9a9a"/> -  -<ImageView in  -Android:layout_width= "Wrap_content" toandroid:layout_height= "Wrap_content" +android:src= "@mipmap/test" -Android:contentdescription= "for showing pictures"/> the</LinearLayout>

Run:

Click the button, you can see the landlord's model is 295*295, belongs to the xhdpi density model, for the comparison, we can view.

And the picture of the display landlord is the use of wrap_content package content, below we move the picture to xxdpi, note: Not copy, is mobile!!!

Run again:

What ghost, the image has become smaller, the illusion?

Once again, move the picture under the HDPI package to see it.

Run:

This time is getting bigger again, it seems that this is not an illusion indeed.

Analysis, we put a picture in a higher density than the mobile phone under the packet, the display will be smaller, and placed in a lower density than the mobile phone package, the picture will automatically enlarge.

I understand that, do not know the right or wrong, cell phone density is like a container, when the cell phone density means that things can be loaded larger, and a similar size of things will appear relatively small, so we see the display of the picture is smaller, and placed under the density of smaller packages, The picture looks relatively larger.

Hey, the opportunistic.

4) Daily development should pay attention to the problem.

According to the development recommendations of Android, we should try to prepare the image resources as far as possible for each density to prepare a set, so that the screen to achieve the best fit, which is also due to the many of our Android models a basic requirement.

The UI, by the way, prepares a set of scales for us, and it's wonderful to think about it.

But, the actual situation is!!!

They will only give you a set of picture resources, yes, the ideal is plump, the reality is very bony, it is true, then we have to face the bleak life, right, how to do it?

According to our test above, we can find that when a picture is placed under a high-density package, the picture will be reduced, except to look at the small dots as if there is nothing, but when the low-density package, the image magnification will inevitably lead to more memory consumption. Because the picture gets bigger, it takes up more pixels, and that inevitably leads to an increase in memory usage.

I believe that many in-service developers have encountered, that is, when your project is slowly getting bigger, when you quote a photo of hdpi pixels, it is very likely that oom will occur, but if placed in high-density XXHDP or xxxhdpi, this situation will not happen.

Through the above analysis, we can also get the conclusion that our best placement should be in the high-density folder, and the current market is the most suitable is xxhdpi.

Well, this section first introduced here, welcome to correct me.

Android Studio you may be ignoring the details--start white screen? What is the meaning of drawable and mipmap? There are all here!!!

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.