本文主要是介绍RelativeLayout中的位置属性,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<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; width: 1045px; overflow: auto; padding: 1px 0px 0px; color: rgb(57, 57, 57); line-height: 21px; margin: 18px 0px !important; background-color: rgb(231, 229, 220);"><div class="bar" style="padding: 0px 0px 0px 45px; margin: 0px;"><div class="tools" style="padding: 3px 8px 10px 10px; font-stretch: normal; font-size: 9px; line-height: normal; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; color: silver; border-left-width: 3px; border-left-style: solid; border-left-color: rgb(108, 226, 108); margin: 0px; background-color: rgb(248, 248, 248);">Java代码 </div></div><ol class="dp-j" start="1" style="padding: 0px 0px 0px 50px; border: none; color: rgb(92, 92, 92); margin: 0px 0px 1px 45px !important; background-color: rgb(255, 255, 255);"><li style="border-style: none none none solid; border-left-width: 3px; border-left-color: rgb(108, 226, 108); list-style: decimal outside; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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; line-height: 14px; margin: 0px !important; padding: 0px 3px 0px 10px !important; background-color: rgb(248, 248, 248);"><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>
这篇关于RelativeLayout中的位置属性的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!