<span id="Label3"></p><p><p><span style="font-size:32px; background-color:rgb(240,240,240)">First of all, what are the spaces that the weights are assigned to?</span></p></p><p><p></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">Weights are proportional to the remaining space of the screen</span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">I can see it without understanding the WORDS.</span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)"><br></span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">If we want the rest of the space to be divided between space 1 and space 2,</span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">We set android:layout_weight= "1" in 2 controls respectively</span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">The above is the analysis of the weight, detailed use of methods such as the following</span></p></p><p><p><span style="font-size:24px; color:rgb(255,153,0)">Let's look at some Code.</span></p></p><p><p></p></p><pre name="code" class="html"><pre name="code" class="html"><span style= "font-size:32px;" ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" match_parent " android:orientation= "horizontal" android:weightsum= "2" > <textview android:layout_width= "wrap_content" android:layout_height= "wrap_content" android:background= "#66ff66" android:layout_ weight= "1" android:text= "face code"/> <textview android:layout_width= "wrap_content" Android : layout_height= "wrap_content" android:background= "#ff0000" android:layout_weight= "1" android: text= "small wood"/></linearlayout></span></pre></pre><p><p></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">This code is a very simple answer. Here is the horizontal direction for the Sample.</span></p></p><p><p>I'll Just say android:weightsum= "2."</p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">This is the total number of weight points. Here I am divided into 2 points,</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">This can be able to not. When you are not very understanding of the weight of the words suggested to</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">of the above code</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"><br></span></p></p><br><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">I set the background color is different, convenient for everyone to see, when the two are divided,</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">The reason is that the initial length of the control is wrap_content, in order to make it easier to distinguish</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">The weights are assigned to the remaining space. Set the initial length to different, see the following code</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"><linearlayoutxmlns:android= "http://schemas.android.com/apk/res/android"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">xmlns:tools= "http://schemas.android.com/tools"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">Android:layout_width= "match_parent"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:layout_height= "match_parent"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:orientation= "horizontal"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:weightsum= "2" ></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"><textview</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">Android:layout_width= "120dp"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:layout_height= "wrap_content"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">Android:background= "#66ff66"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:layout_weight= "1"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:text= "face code"/></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"><textview</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">Android:layout_width= "30dp"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:layout_height= "wrap_content"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">Android:background= "#ff0000"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:layout_weight= "1"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px">android:text= "small wood"/></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="font-size:24px"></LinearLayout></span></p></p><span style="font-size:24px"><span style="font-size:24px"></span></span><p><p><br></p></p><p><p><span style="font-size:24px">It's obviously different, because of the Two. control initialization length</span></p></p><p><p><span style="font-size:24px">Not the same, divide the rest of the space to them after their</span></p></p><p><p><span style="font-size:24px">And the length will be Different.</span></p></p><p><p><span style="font-size:24px">This is the whole project after the layout of my understanding of the weight,</span></p></p><p><p><span style="font-size:24px">By the way, I usually set the android:layout_width= "0dp" in the Project.</span></p></p><p><p><span style="font-size:24px">The code still uses it.</span></p></p><p><p><span style="font-size:24px"></span></p></p><pre name="code" class="html"><pre name="code" class="html"><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" match_parent " android:orientation= "horizontal" android:weightsum= "2" > <textview android:layout_width= "0dp" android:layout_height= "wrap_content" android:background= "#66ff66" android:layout_weight= "1" android:text= "face code"/> <textview android:layout_width= "0dp" android:layout_height= " Wrap_content " android:background=" #ff0000 " android:layout_weight=" 1 " android:text=" small wood "/>< /linearlayout></pre></pre>Why do you want to set the length to 0? It's going to be the first thing I've Written.<p><p></p></p><p><p><span style="font-size:24px"></span></p></p><p align="left"><p align="left"><span style="color:#FF9900">In order to better allocate the rest of the Space. Ignores the initial Length.</span></p></p><p align="left"><p align="left"><span style="color:#FF9900"></span> <span style="color:#FF9900">The above is my understanding,</span></p></p><p align="left"><p align="left"><span style="color:#FF9900">supplemented by</span> <span style="color:#FF9900">http://blog.csdn.net/qq_33210042/article/details/50902052</span></p></p><p align="left"><p align="left"><span style="color:#FF9900">That's in the last Picture.</span></p></p><br><p align="left"><p align="left">in <span style="color:#FF9900">development, you will often encounter putting words in the middle of a control</span> <span style="color:#FF9900">ViewGroup</span> <span style="color:#FF9900">sliding at the same time</span></p></p><p align="left"><p align="left"><span style="color:#FF9900">Can change the color of the Font. Detailed implementation will not say, here the layout</span></p></p><p align="left"><p align="left"><span style="color:#FF9900"><br></span></p></p><p align="left"><p align="left"><span style="color:#FF9900"></span></p></p><p align="left"><p align="left"><span style="color:#FF9900">That's the kind of thing we want. Swipe left and right to switch at the same time,</span></p></p>of course, sometimes more than 2, then the weight of more than a FEW.<p align="left"><p align="left"><span style="color:#FF9900">Look at the code for the layout</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"><linearlayoutxmlns:android= "http://schemas.android.com/apk/res/android"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">xmlns:tools= "http://schemas.android.com/tools"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">Android:layout_width= "match_parent"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:layout_height= "match_parent"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:orientation= "horizontal"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:weightsum= "2" ></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"><textview</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">Android:layout_width= "0dp"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:layout_height= "wrap_content"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">Android:background= "#66ff66"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:gravity= "center"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:layout_weight= "1"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:text= "</span> <span style="color:#FF9900">Face Code "/></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"><textview</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">Android:layout_width= "0dp"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:layout_height= "wrap_content"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">Android:background= "#ff0000"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:gravity= "center"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:layout_weight= "1"</span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900">android:text= "</span> <span style="color:#FF9900">Small Wood "/></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"></span></p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)"><span style="color:#FF9900"></LinearLayout></span></span></p></p><p align="left"><p align="left"><span style="color:#FF9900">Use the</span></p></p><p align="left"><p align="left">Android:gravity is where the current control content is Displayed.</p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)">Here I am by the way, assuming that there is no layout to ignore the children's shoes</p></p><p align="left" style="background:rgb(240,240,240)"><p align="left" style="background:rgb(240,240,240)">Follow my Blog. I will make a progress together.</p></p><br><p><p><br></p></p><pre name="code" class="html" style="color:rgb(255,153,0); font-size:24px"><pre name="code" class="html" style="color:rgb(255,153,0); font-size:24px"></pre></pre><p align="left"><p align="left"><br></p></p><br><br> <p><p>Detailed analysis of Android weight (weight)</p></p></span>
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