RelativeLayout相对布局和LinearLayout线性布局属性

    LinearLayout(线性布局)   

            LinearLayout布局只有两种排版方式:水平排列和垂直排列。

           LinearLayout用 android:orientation控制控件排列的方式:

                   android:orientation="vertical"垂直排列(新建的布局默认垂直排列)

                   android:orientation="horizontal"水平排列

                  如果LinearLayout是第一个父容器那么LinearLayout中一定要写android:orientation语句如果是子容器可以不要,但是子容器默认水平排列。

           layout_gravity控件在父容器的位置

                  android:layout_gravity="top"                                  控件在父容器的上边,左右下 left,right,bottom

                  android:layout_gravity="center"                             控件在父容器中居中

                  android:layout_gravity="center_vertical"              控件在父容器的垂直方向居中,水平方向居中center_horizontal

                  android:gravity="top"                                              内容在控件的上边      左右下 left,right,bottom   

                  android:gravity="center"                                         内容在控件中居中     vertical垂直居中,center_horizontal水平居中

                  android:gravity="bottom|right"                              内容在控件的右下方,right|bottom也可以,right|top右上方,left|top左上方

                  android:layout_weight="1"                                     比重,占布局的1/总   (注意:在使用weight时如果LinearLayout布局是orientation="vertical"垂直排列android:layout_height要设置为0dp,orientation="horizontal"时layout_width="0dp",不然布局会出现问题.

                          

   RelativeLayout(相对布局)

                 相对布局顾名思义,控件的位置是相对的。RelativeLayout的特点就是控件的位置是相对的容易控制。

                 android:layout_toRightOf="@+id/xxx"                             该控件在xxx控件的右边

                 android:layout_toLeftOf="@+id/xx"                                  该控件在xxx控件的左边

                 android:layout_above="@+id/xxx"                                    该控件在xxx控件的上边

                 android:layout_below="@+id/xxx"                                    该控件在xxx控件的下边

                 android:layout_alignLeft="@+id/xxx"                               该控件的左边与xxx控件的左边对齐

                 android:layout_alignTop="@+id/xxx"                               该控件的上边与xxx控件的上边对齐

                 android:layout_alignBottom="@+id/xxx"                         该控件的下边与xxx控件的下边对齐

                 android:layout_alignRight="@+id/xxx"                             该控件的右边与xxx控件的右边对齐

                 android:layout_alignParentLeft="true"                             该控件的左边与父控件的左边对齐

                android:layout_alignParentTop="true"                             该控件的上边与父控件的上边对齐

                android:layout_alignParentRight="true"                          该控件的右边与父容器的右边对齐

               android:layout_alignParentBottom="true"                        该控件的下边与父容器的下边对齐(这个属性有的时候应为自己的布局问题会出现没有效果的问题,这时候就要重新写一个布局包裹这个布局

                 <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" >

             <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

                < /RelativeLayout>)

               android:layout_centerInParent="true"                             该控件在父控件中居中

               android:layout_centerVertical="true"                              该控件在父控件中垂直居中

                android:layout_centerHorizontal="true"                        该控件在父控件中水平居中


  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值