LinearLayout中的layout_weight属性

    [size=large;]linearlayout中的layout_weight属性[/size]
 
 
[size=medium;]布局linearlayout代码[/size]
 
<?xml version="1.0" encoding="utf-8"?><linearlayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    >  <button      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:text="button1"      android:background="#008000"      android:layout_weight="0"/><button      android:layout_width="fill_parent"      android:layout_height="fill_parent"      android:text="button2"      android:background="#ffff00"      android:layout_weight="0"/></linearlayout>
 
[size=large;]layout_weight属性如果没有设置,则默认为0.[/size]
 
 
[size=medium;]按钮1:button1,绿色[/size]
[size=medium;]按钮2:button2,黄色[/size]
 
<span style="color: #008000; font-size: large;">下面以按钮1和按钮2的weight属性(layout_weight)的变化,分别进行记录。</span>
 
 
<span style="color: #ff0000; font-size: medium;">这里测试的是垂直布局android:orientation="vertical",所以针对组件的</span><span style="color: #ff0000; font-size: medium;"><span><span><span class="attribute">android:layout_height属性;如果测试的水平布局,则需针对组件的</span></span></span><span><span><span class="attribute">android:layout_width属性。</span></span></span></span>
 
 
<span style="color: #ff0000; font-size: medium;">(一) </span><span><span style="color: #ff0000; font-size: medium;"><span class="attribute">android:layout_height</span><span>=</span><span class="attribute-value">"fill_parent"</span></span></span>
 
 
<table border="0"><tbody><tr><td><img src="http://dl.iteye.com/upload/attachment/532613/695fc007-f4df-3d2d-9e67-8c403686868b.png" alt=""><br></td><td><img src="http://dl.iteye.com/upload/attachment/532615/8a8c014d-a8aa-3a92-a763-39155c869f35.png" alt=""></td></tr><tr><td>[size=small;] button1(weight=0) button2(weight=0)[/size]</td><td>[size=small;] button1(weight=0) button2(weight=1)[/size]</td></tr><tr><td><br><img src="http://dl.iteye.com/upload/attachment/532640/e2151cbe-6a58-3de0-8caf-42b3e5051a25.png" alt=""><br> </td><td><br><img src="http://dl.iteye.com/upload/attachment/532643/e45fecf3-be63-354c-9aec-4efb7794e64d.png" alt=""><br> </td></tr><tr><td>[size=small;]button1(weight=1) button2(weight=1)[/size]
button1占1/2,button2占1/2
</td><td>[size=small;]button1(weight=1) button2(weight=2)[/size]
button1占2/3,button2占1/3
</td></tr><tr><td><br><img src="http://dl.iteye.com/upload/attachment/532650/9ea53887-78b4-3607-9a0b-5f251807b219.png" alt=""><br> </td><td><br><img src="http://dl.iteye.com/upload/attachment/532654/8630fbe4-6cd4-3e18-987e-7788814f71d6.png" alt=""><br> </td></tr><tr><td>[size=small;]button1(weight=1) button2(weight=9)[/size]
button1占9/10,button2占1/10
</td><td>[size=small;]button1(weight=1) button2(weight=30)[/size]
button1占30/31,button2占1/31
</td></tr><tr><td></td><td></td></tr></tbody></table> 
 
<span style="color: #ff0000; font-size: medium;">(二) </span><span><span style="color: #ff0000; font-size: medium;"><span class="attribute">android:layout_height</span><span>=</span><span class="attribute-value">"wrap_content"</span></span></span>
 
<table border="0"><tbody><tr><td><br><img src="http://dl.iteye.com/upload/attachment/532665/5a819fae-3a3f-37cd-a0af-a4359b5d780f.png" alt=""><br> </td><td><br><img src="http://dl.iteye.com/upload/attachment/532669/d07892a0-09d9-35d9-a50c-620ccf61dc4b.png" alt=""><br> </td></tr><tr><td>[size=small;]button1(weight=0) button2(weight=0)[/size]
</td><td>[size=small;]button1(weight=0) button2(weight=1)[/size]</td></tr><tr><td><br><img src="http://dl.iteye.com/upload/attachment/532677/b8f97960-b671-3fe0-902b-6ef3ade4bcdd.png" alt=""><br> </td><td><br><img src="http://dl.iteye.com/upload/attachment/532679/59fd5098-82d4-376a-b385-1145b2b1cebd.png" alt=""><br> </td></tr><tr><td>[size=small;]button1(weight=1) button2(weight=1)[/size]
button1占1/2,button2占1/2
</td><td>[size=small;]button1(weight=1) button2(weight=2)[/size]
button1占1/3,button2占2/3
</td></tr><tr><td><br><img src="http://dl.iteye.com/upload/attachment/532681/3fd19667-a949-3de0-a91c-b84c08355d8b.png" alt=""><br> </td><td><br><img src="http://dl.iteye.com/upload/attachment/532683/8d36dbd1-973d-37ff-a1d1-488a62bd5a17.png" alt=""><br> </td></tr><tr><td>[size=small;]button1(weight=1) button2(weight=9)[/size]
 
</td><td>[size=small;]button1(weight=1) button2(weight=30)[/size]
 
</td></tr><tr><td></td><td></td></tr><tr><td></td><td></td></tr></tbody></table> 
<span style="color: #008000; font-size: large;">通过以上实验可知:</span>
<span style="color: #ff0000; font-size: medium;">(一) </span><span><span style="color: #ff0000; font-size: medium;"><span class="attribute">android:layout_height</span><span>=</span><span class="attribute-value">"fill_parent"</span></span></span>
<span style="color: #ff0000; font-size: medium;">(二) </span><span><span style="color: #ff0000; font-size: medium;"><span class="attribute">android:layout_height</span><span>=</span><span class="attribute-value">"wrap_content"</span></span></span>
<span style="color: #008000; font-size: large;">在(一)、(二)2种情况在相同的weight属性下呈现出正好相反的情况。</span>
 
 
 
 
 
 

你可能感兴趣的:(java,工作)