Android中RelativeLayout各个属性 android:layout_alignParentLeft="true"找不到有时候

本文详细介绍了Android中RelativeLayout的布局属性,如`android:layout_alignParentLeft="true"`等,强调了当该属性无法生效时可能的原因是父控件并非RelativeLayout。正确使用这些属性能实现精确的界面元素对齐。

android:layout_above="@id/xxx"  --将控件置于给定ID控件之上
android:layout_below="@id/xxx"  --将控件置于给定ID控件之下

android:layout_toLeftOf="@id/xxx"  --将控件的右边缘和给定ID控件的左边缘对齐
android:layout_toRightOf="@id/xxx"  --将控件的左边缘和给定ID控件的右边缘对齐

android:layout_alignLeft="@id/xxx"  --将控件的左边缘和给定ID控件的左边缘对齐
android:layout_alignTop="@id/xxx"  --将控件的上边缘和给定ID控件的上边缘对齐
android:layout_alignRight="@id/xxx"  --将控件的右边缘和给定ID控件的右边缘对齐
android:layout_alignBottom="@id/xxx"  --将控件的底边缘和给定ID控件的底边缘对齐
android:layout_alignParentLeft="true"  --将控件的左边缘和父控件的左边缘对齐
android:layout_alignParentTop="true"  --将控件的上边缘和父控件的上边缘对齐
android:layout_alignParentRight="true"  --将控件的右边缘和父控件的右边缘对齐
android:layout_alignParentBottom="true" --将控件的底边缘和父控件的底边缘对齐
android:layout_centerInParent="true"  --将控件置于父控件的中心位置
android:layout_centerHorizontal="true"  --将控件置于水平方向的中心位置
android:layout_centerVertical="true"  --将控件置于垂直方向的中心位置

其中很重要的android:layout_alignParentLeft="true"  --将控件的左边缘和父控件的左边缘对齐有时候找不到知道为啥?

那是因为你的父控件不是相对布局,当你的父控件是相对布局,子控件才能显示这个属性哦,大家要注意哦

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/beijing" tools:ignore="ExtraText"> <!-- 头像 --> <ImageView android:id="@+id/iv_avatar" android:layout_width="100dp" android:layout_height="100dp" android:layout_centerHorizontal="true" android:layout_marginTop="100dp" android:src="@drawable/touxiang" android:scaleType="centerCrop" /> <!-- 新增:QQ文本 --> <!-- 账号输入框 --> <TextView android:id="@+id/textView_user" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/password" android:layout_alignBottom="@+id/password" android:layout_alignParentLeft= "true" android:text="账号" android:textColor="#FFFFFF" android:textSize="20dp" tools:ignore="UnknownId" /> <TextView android:id="@+id/textView_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/user" android:layout_alignBottom="@+id/user" android:layout_alignParentLeft="true" android:text="密码 android:textColor=" tools:ignore="UnknownId" />#FFFFFF" android:textSize="20dp"/> <!-- 登录和注册按钮 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/textView_password" android:layout_margin="16dp" android:orientation="horizontal" android:weightSum="2" tools:ignore="UnknownId"> <Button android:id="@+id/btn_login" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> <Button android:id="@+id/btn_register" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> </LinearLayout> <!-- 同意 QQ 服务协议文本 --> <TextView android:id="@+id/tv_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="16dp" android:text="同意 QQ 服务协议" /> </RelativeLayout> 将上述代码调整顺序,账号密码在头像下面,登陆注册在密码下面
最新发布
09-22
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/beijing" tools:ignore="ExtraText"> <!-- 头像 --> <ImageView android:id="@+id/iv_avatar" android:layout_width="100dp" android:layout_height="100dp" android:layout_centerHorizontal="true" android:layout_marginTop="100dp" android:src="@drawable/touxiang" android:scaleType="centerCrop" /> <!-- 账号输入框 --> <TextView android:id="@+id/textView_user" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/iv_avatar" android:layout_marginTop="20dp" android:layout_alignParentLeft="true" android:text="账号" android:textColor="#FFFFFF" android:textSize="20dp" tools:ignore="UnknownId" /> <!-- 密码输入框 --> <TextView android:id="@+id/textView_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/textView_user" android:layout_marginTop="10dp" android:layout_alignParentLeft="true" android:text="密码" android:textColor="#FFFFFF" android:textSize="20dp" tools:ignore="UnknownId" /> <!-- 登录和注册按钮 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/textView_password" android:layout_margin="16dp" android:orientation="horizontal" android:weightSum="2" tools:ignore="UnknownId"> <Button android:id="@+id/btn_login" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="登录" /> <Button android:id="@+id/btn_register" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="注册" /> </LinearLayout> <!-- 同意 QQ 服务协议文本 --> <TextView android:id="@+id/tv_agreement" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="16dp" android:text="同意 QQ 服务协议 " /> </RelativeLayout> 怎样给账号和密码添加输入的文本框,同时在最下面的同意QQ服务协议前也添加一个小正方形的文本框,最后将账号密码和登陆注册按钮的间距变大,账号密码同意QQ服务颜色改变
09-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值