Want to thank a partner today

The nickname of this little partner is:

Chen Xiaoyuan

If you usually open a lot of official accounts, then you must know this series:

This interaction blows up the thirteenth style of the series

This interactively blows up the twelfth style of the series There are fish every year

....

Just look at the name and you know that there are at least thirteen articles, you can go to the author's blog to learn.

The quality of each article is very high.

But the main reason for thanks is not this.

Retroactive Q&A

I still remember that at the end of May, the Q&A on Android was launched:

Come out to play on Android

I have probably posted more than 10 questions:

Want to thank a partner today
In fact, posting a question is a very boring thing. Sometimes it has been posted for a few days and no one has answered it. It will gradually form a very negative emotion, denying the function and even the self:

This function has a child with chicken, how can precipitate formed it .. .

The most memorable one was when I posted a Binder question. After hanging up for a few days, no one answered it. I started to give up on myself (look at the picture carefully, binder takes the next question, the cycle is close to half a month). Fortunately, he, That's right, this man, at me in the group, ask me a question?

Pull me back from the edge of giving up.

So in this quiet moment of the night, I counted all the questions, and classmate Chen Xiaoyuan la la la answered almost all of my questions.

I counted it and there was only one question. There was no answer related to the gradle plugin. The others were answered.

To be honest, there is no answer from Xiaoyuan, this function I am ready to fall into the sea.

I would like to express my sincere thanks.

The original intention of the question and answer

In fact, I originally did the question and answer function, mainly for learning questions. What do you mean?

The meaning of the question and answer is actually to check the gaps for everyone, or the content that has not been understood before, just learn it, and finally come back to answer and summarize.

On a larger scale, the entire website is leaning towards learning, that is, it can only be used as an article when you want to learn.

Today's dry goods

Listening to me talking so much, if you don’t add some dry goods, it feels like a waste of one push, and it’s a loss.

So today I will mainly post a question and answer.

Detailed description of MesureSpec.UNSPECIFIED when customizing View measurement

I believe most of you can say the custom steps, but many details also need attention.

For MesureSpec.UNSPECIFIED

  1. When will this mode be encountered?

  2. What to do after encountering it?

  3. What are the precautions?

I basically ask this question during interviews, but there are very few students who can answer it.

UNSPECIFIED means unspecified. In this mode, the parent control will not interfere with the desired size of the child View.

So, when will this mode be encountered in onMeasure:

In fact, it depends on its parent container.

Take the most commonly used RecyclerView as an example. When the item is measured, if the list is scrollable and the width or height of the item is set to WRAP_CONTENT, then the onMeasure method of the itemView will receive MesureSpec.UNSPECIFIED .

Open the RecyclerView source code, and you will see this comment in the getChildMeasureSpec method:

“MATCH_PARENT can't be applied since we can scroll in this dimension, wrap instead using UNSPECIFIED.”

What it wants to express is: In a scrollable ViewGroup, the size of the Item should not be limited (if it is scrolled horizontally, the width is not limited), why?

Because it can be scrolled, no matter how wide and high the Item is, you can still see the part that was blocked before scrolling.

Some students may have questions:

I set wrap_content, and the AT_MOST should be received in onMeasure. Why is it forced to become UNSPECIFIED?

This is because considering that the size of the Item may exceed the size of this scrollable ViewGroup, and in AT_MOST mode, your size cannot exceed the size of the ViewGroup you are in, at most it can only be equal to. Therefore, it is more appropriate to use UNSPECIFIED. In this mode, you can be as big as you want.

So, when we customize the View, what should we do when we find the UNSPECIFIED mode during the measurement :

This is more free. Since the size is determined by myself, I can write it as 50 or fix it as 200.

But it is still recommended to define it according to actual needs.

For example, ImageView, its approach is: if there is a set image content (drawable), it will directly use the size of the drawable, but it will not exceed the specified MaxWidth or MaxHeight, if there is no content, it will be 0.

The way TextView handles UNSPECIFIED is the same as AT_MOST.

Of course, these dimensions are not necessarily equal to the dimensions of the final layout, because the final decision on the position and size of the child View is in the onLayout method, where you can completely ignore these dimensions and lay out as you want.

However, this is generally not done.

From: Xiaoyuan's answer.

Unexpected discovery

There is a public account owner nanchen, who received what I did before:

I’m sharing Android in a group. It seems that no one talks anymore... Issue 3

It's an inspiration. Asking this thing every day, it seems to be very easy to be honest, it is too difficult to stick to it.

I am also updating some daily questions. I don’t know how long it will last, but I still like him. The article is probably as follows:

Question of the day: talk about the class loading mechanism of the Java virtual machine

At last

I still remember the first time he chatted with Xiaoyuan, he was still struggling with how to chase the goddess, and recently discovered that he was already buying books for his girlfriend!

It should be good people get good rewards.

Hehehe~

Well, Xiaoyuan should not be under pressure, and don't make any changes in your mentality because of this article, and take the answer as a task. In fact, you should answer when you want to answer. You should cook and live your day easily!

Recommended reading:

Teach you to write a barrage library, sure you don’t know?

Android Quality Technology Sharing | Issue 6

Interview questions shared by major mobile companies in March 19

Guess you like

Origin blog.51cto.com/15064646/2572821