今天在群里看到有人提到layout_alignRight 这种属性,自己想了半天居然没有了印象
赶紧写一个布局看看这个相对布局的属性
先看下自己常用的属性
android:alignParentBottom
android:layout_alignParentLeft
android:layout_alignParentRight
android:layout_alignParentTop
这四个控件一般属性设置为true 它们相对于父布局的相对位置 ,它们的属性依赖于父布局的RelativeLayout
在看 下面的属性
android:layout_alignRight
android:layout_alignBottom
android:layout_alignTop
android:layout_alignLeft
它们的属性一般相对于指定id的位置,不依赖与父布局的RelativeLayout
想入现在 一个相对布局宽和高都是match_parent
画下面的图
textView 使用android:layout_alignParentRight 位于了右边 但是高度不好设置了
当然大家一般都不会把最外的层的相对布局高度设为为match_parent
这个时候使用相对某个控件的设置还是很好使用的
代码如下
android:layout_alignTop="@+id/edt"
android:layout_alignRight="@+id/edt"
android:layout_alignBottom="@+id/edt"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/edt"
android:layout_width="400dp"
android:layout_height="100dp"
android:background="@null"
android:hint="请输入手机号" />
<TextView
android:id="@+id/txt"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignTop="@+id/edt"
android:layout_alignRight="@+id/edt"
android:layout_alignBottom="@+id/edt"
android:layout_marginTop="25dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="25dp"
android:background="@drawable/drawable_txt"
android:gravity="center"
android:text="获取验证码" />
</RelativeLayout>
这个就是相对于某一个控件的id 来控制很不错的选择,比如购物车上的数量,等等,方法有很多中,这种方法必能被遗忘
学而时习之,温故而知新。。。
岁月推动着年华,伴随着流水的脚步走过春夏秋冬。回想一路走来磕磕绊绊,感谢前辈们的无私奉献,本文重在共享,欢迎大家转载,评论,指教,点赞,谢谢,如果您对文章存在疑问,或者和您的文章类似,请私信,----------------期待是心痛的根源,心不动,则不痛。