android layout 相關

http://blog.csdn.net/lamp_zy/article/details/8035161

<p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);">1、 相對佈局的基本概念 <br style="margin: 0px; padding: 0px;" />一個控件的位置它決定於它和其他控件的關係,好處:比較靈活;缺點:掌握比較複雜。 <br style="margin: 0px; padding: 0px;" />2、 相對佈局常用屬性介紹 <br style="margin: 0px; padding: 0px;" />這裏將這些屬性分成4個組,便於理解和記憶。 <br style="margin: 0px; padding: 0px;" />a)、以下4個屬性設置控件與之間的關係和位置 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109500394.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />但是上面4個屬性並沒有設置各個控件之間是否對齊。 <br style="margin: 0px; padding: 0px;" />示例1:將控件A放置在控件B的上面,則使用android:layout_above屬性,控件佈局的效果可以有以下這麼兩種情況。 <br style="margin: 0px; padding: 0px;" />1、 控件A與控件B對齊,並且控件A是在控件B的上面。 <br style="margin: 0px; padding: 0px;" />2、 控件A沒有與控件B對齊,但是控件A又確實是在控件B的上面。 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109501874.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"> </p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109502928.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />b)、以下5個屬性,設置的是控件與控件之間對齊的方式(是頂部、底部還是左、右對齊)。 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109504048.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />示例2:在示例1的基礎上,設置控件A放置在控件B的上面,使用android:layout_above屬性,並且控件A的右邊邊緣與控件B的右邊邊緣對齊,使用android:layout_alignRight屬性。 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109505182.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />c)、以下4個屬性設置控件與父控件之間對齊的方式(是頂部、底部還是左、右對齊)。 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109510137.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />d)、以下4個屬性設置控件的方向。 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109511276.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />可以通過組合這些屬性來實現各種各樣的佈局。 <br style="margin: 0px; padding: 0px;" />注:以上屬性和其他更多屬性的作用都能在android的幫助文檔中找到; <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />示例3:假如要實現一個如下圖這樣佈局的程序 <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109512937.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" />如果這樣的佈局要使用LinearLayout的話會比較麻煩和複雜, <br style="margin: 0px; padding: 0px;" />1、 首先需要一個垂直佈局方向的LinearLayout,包裹所有的控件; <br style="margin: 0px; padding: 0px;" />2、 然後在第一個LinearLayout中嵌套一個垂直方向的LinearLayout,放在上部分,在這個LinearLayout中放入一個TextView和EditText; <br style="margin: 0px; padding: 0px;" />3、 最後還是在第一個LinearLayout中嵌套一個水平方向的LinearLayout,放在第一個LinearLayout的下部分,在這個LinearLayout中放入兩個Button,並且還得讓它們居右。 <br style="margin: 0px; padding: 0px;" />可參考下圖: <br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><img src="http://pic002.cnblogs.com/images/2011/168345/2011120109514498.jpg" alt="" style="border: 0px; max-width: 100%; margin: 0px; padding: 0px;" /></p><p style="margin: 5px auto; padding-top: 0px; padding-bottom: 0px; color: rgb(57, 57, 57); font-family: verdana, 'ms song', Arial, Helvetica, sans-serif; line-height: 21px; background-color: rgb(250, 247, 239);"><br style="margin: 0px; padding: 0px;" /><br style="margin: 0px; padding: 0px;" />如果使用RelativeLayout會要簡單很多,下面爲main.xml的代碼。 </p><div class="dp-highlighter" style="font-family: Consolas, 'Courier New', Courier, mono, serif; background-color: rgb(231, 229, 220); width: 1045px; overflow: auto; padding: 1px 0px 0px; color: rgb(57, 57, 57); line-height: 21px; margin: 18px 0px !important;"><div class="bar" style="padding: 0px 0px 0px 45px; margin: 0px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; background-color: rgb(248, 248, 248); border-left-width: 3px; border-left-style: solid; border-left-color: rgb(108, 226, 108); margin: 0px;">Java代碼 </div></div><ol class="dp-j" start="1" style="padding: 0px 0px 0px 50px; border: none; list-style-position: initial; list-style-image: initial; background-color: rgb(255, 255, 255); color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important;"><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"><?xml version=</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"1.0"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;"> encoding=</span><span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"utf-8"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">?>  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"><RelativeLayout xmlns:android=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"http://schemas.android.com/apk/res/android"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    android:layout_width=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"fill_parent"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    android:layout_height=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    android:padding=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"10px"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    >  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <TextView  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:id=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@+id/lable"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:text=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"Type here:"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_width=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"fill_parent"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_height=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    />  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">      </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <EditText  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:id=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@+id/entry"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_width=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"fill_parent"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_height=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:background=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@android:drawable/editbox_background"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_below=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@id/lable"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    />  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">      </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <Button  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:id=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@+id/ok"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_width=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_height=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:text=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"OK"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_below=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@id/entry"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_marginLeft=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"10px"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_alignParentRight=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"true"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    />  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">      </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    <Button  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:id=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@+id/cancel"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_width=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_height=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"wrap_content"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_toLeftOf=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@id/ok"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:layout_alignTop=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"@id/ok"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">        android:text=<span class="string" style="margin: 0px; padding: 0px; border: none; color: blue; background-color: inherit;">"Cancel"</span><span style="margin: 0px; padding: 0px; border: none; background-color: inherit;">  </span></span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;">    />  </span></li><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; background-color: rgb(248, 248, 248); line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important;"><span style="margin: 0px; padding: 0px; border: none; color: black; background-color: inherit;"></RelativeLayout>  </span></li></ol></div><span style="line-height: 22px;">3.</span><span style="font-size: 10px;">gravity和layout_gravity</span>
<span style="line-height: 26px; font-size: 10px;">android:gravity</span><span style="line-height: 26px; font-size: 10px;">  </span><br style="line-height: 26px; font-size: 10px;" /><span style="line-height: 26px; font-size: 10px;">android:gravity屬性是對該view 內容的限定.比如一個button 上面的text.  你可以設置該text 在view的靠左,靠右等位置.以button爲例,android:gravity="right"則button上面的文字靠右 </span><br style="line-height: 26px; font-size: 10px;" /><br style="line-height: 26px; font-size: 10px;" /><span style="line-height: 26px; font-size: 10px;">android:layout_gravity</span><span style="line-height: 26px; font-size: 10px;"> </span><br style="line-height: 26px; font-size: 10px;" /><span style="line-height: 26px; font-size: 10px;">android:layout_gravity是用來設置該view相對與起父view 的位置.比如一個button 在linearlayout裏,你想把該button放在靠左、靠右等位置就可以通過該屬性設置.以button爲例,android:layout_gravity="right"則button靠右 </span>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章