Android--RelativeLayout

it2022-05-28  77

相对布局(RalativeLayout)

  是指相对于其他部件或者父部件的布局方式。  

 1、相对于容器定位:  

  android:layout_alignParentTop  将部件的顶部与容器的顶部对齐。    

  android:layout_alignParentBottom   

  android:layout_alignParentLeft    

  android:layout_alignParentRight    

  android:layout_centerHorizontal 将部件放在容器的垂直居中    

  android:layout_centerVertical 水平居中    

  android:layout_centerInParent 水平和垂直居中    

    【这些属性的值都是一个布尔值true false】   

2、关联记号    1)、@+id/为所有的元素的添加id    2)、@id/ 用来引用其他部件    【例】部件A  @+id/widget_a,那么另外一个部件B可以通过标示符@id/widget_a引用该部件。  

 3、相对其他部件的位置。。     

android:layout_above     

android:layout_below 在一个一个部件的下面     

android:layout_toLeftOf     

android:layout_toRightOf          

 

和其他部件的对齐方式     

android:layout_alignTop是该部件与被引用的部件顶端对齐     

android:layout_alignBottom   

android:layout_alignRight  右边对齐     

android:layout_alignLeft     

android:layou_alignBaseline 两个部件相对于基线对齐      所谓基线就是文本恰好位于其上的一条看不见的线。

 

 

<一段XML文件,显示使用方法>

<?xml version = "1.0" encoding = "utf-8" ?> <RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:padding = "5px" > <TextView android:id = "@+id/label" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "URL:" android:padding = "15px"/> <EditText android:id = "@+id/entry" android:layout_width = "fill_parent" android:layout_height = "wrap_content" android:layout_toRightOf = "@id/label" android:layout_alignBaseline = "@id/label" /> <Button android:id = "@+id/ok" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_below = "@id/entry" android:layout_alignRight = "@id/entry" android:text = "OK" /> <Button android:id = "@+id/cancel" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:layout_toLeftOf = "@id/ok" android:layout_alignTop = "@id/ok" android:layout_alignBottom = "@id/ok" android:text= "Cancel" /> </RelativeLayout> View Code

 

转载于:https://www.cnblogs.com/plxx/p/3446364.html

相关资源:Android-DragView可拖拽的view继承自RelativeLayout

最新回复(0)