RelativeLayout中的位置属性

2023-12-21 19:32

本文主要是介绍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中的位置属性的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/521227

相关文章

spring中的@MapperScan注解属性解析

《spring中的@MapperScan注解属性解析》@MapperScan是Spring集成MyBatis时自动扫描Mapper接口的注解,简化配置并支持多数据源,通过属性控制扫描路径和过滤条件,利... 目录一、核心功能与作用二、注解属性解析三、底层实现原理四、使用场景与最佳实践五、注意事项与常见问题六

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as

springboot项目打jar制作成镜像并指定配置文件位置方式

《springboot项目打jar制作成镜像并指定配置文件位置方式》:本文主要介绍springboot项目打jar制作成镜像并指定配置文件位置方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录一、上传jar到服务器二、编写dockerfile三、新建对应配置文件所存放的数据卷目录四、将配置文

python3如何找到字典的下标index、获取list中指定元素的位置索引

《python3如何找到字典的下标index、获取list中指定元素的位置索引》:本文主要介绍python3如何找到字典的下标index、获取list中指定元素的位置索引问题,具有很好的参考价值,... 目录enumerate()找到字典的下标 index获取list中指定元素的位置索引总结enumerat

Python打印对象所有属性和值的方法小结

《Python打印对象所有属性和值的方法小结》在Python开发过程中,调试代码时经常需要查看对象的当前状态,也就是对象的所有属性和对应的值,然而,Python并没有像PHP的print_r那样直接提... 目录python中打印对象所有属性和值的方法实现步骤1. 使用vars()和pprint()2. 使

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

SpringBoot读取ZooKeeper(ZK)属性的方法实现

《SpringBoot读取ZooKeeper(ZK)属性的方法实现》本文主要介绍了SpringBoot读取ZooKeeper(ZK)属性的方法实现,强调使用@ConfigurationProperti... 目录1. 在配置文件中定义 ZK 属性application.propertiesapplicati

Java反射实现多属性去重与分组功能

《Java反射实现多属性去重与分组功能》在Java开发中,​​List是一种非常常用的数据结构,通常我们会遇到这样的问题:如何处理​​List​​​中的相同字段?无论是去重还是分组,合理的操作可以提高... 目录一、开发环境与基础组件准备1.环境配置:2. 代码结构说明:二、基础反射工具:BeanUtils

MySQL 事务的概念及ACID属性和使用详解

《MySQL事务的概念及ACID属性和使用详解》MySQL通过多线程实现存储工作,因此在并发访问场景中,事务确保了数据操作的一致性和可靠性,下面通过本文给大家介绍MySQL事务的概念及ACID属性和... 目录一、什么是事务二、事务的属性及使用2.1 事务的 ACID 属性2.2 为什么存在事务2.3 事务