irpas技术客

有关android studio的相对布局的问题_准程序媛!_android studio相对布局代码

未知 2996

按钮3的 layout_toRightOf 写成 @+id/btn_one 时可以显示,写成 @+id/btn_two 时预览界面中的按钮3就不见了

?下面是全部的代码:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="20dp"> <Button android:id="@+id/btn_one" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:text="按钮1"/> <Button android:id="@+id/btn_two" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_margin="260dp" android:text="按钮2"/> <Button android:id="@+id/btn_three" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBottom="@id/btn_two" android:layout_marginBottom="100dp" android:layout_toRightOf="@+id/btn_two" android:text="按钮3"/> </RelativeLayout>

下面这些是运行的截图:

(只有粉色部分有改动,从one改成了two)

?

经过不断查找,发现自己犯了一个很愚蠢的问题!

修改前的按钮2中写的是:

android:layout_margin="260dp"

修改后的代码为:

android:layout_marginTop="260dp"

少写了一个Top!

修改后的运行界面是这样的:

android:layout_margin意思是设置view的上下左右边框的额外空间

android:layout_marginTop意思是设置当前控件上边界与某控件的距离

与此相关的还有marginBottom,marginLeft,marginRight分别表示当前控件的底边界,左边界,右边界与某控件的距离。

p1中之所以按钮3可以显现是因为按钮1的设置没有问题

p2出错就是因为marginTop写成了margin,按钮3也没有不见,只是显示在了屏幕外面

p3改正之后按钮3就像预期的那样出现啦!

以后一定要多多注意鸭!


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #Android #studio相对布局代码 #按钮3的 #写成 #idbtn_one #时可以显示写成 #idbtn_two