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"                        该控件的下边与父容器的下边对齐(这个属性有的时候应为自己的布局问题会出现没有效果的问题,这时候就要重新写一个布局包裹这个布局

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

                         android:layout_height="wrap_content"/>

                < /RelativeLayout>)

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

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

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


更多相关文章

  1. Android(安卓)XML属性在文档中的位置
  2. Android进阶(二十二)设置TextView文字水平垂直居中
  3. Android常用控件之悬浮窗
  4. Android自带的时间空间和日期控件
  5. 《Android开发从零开始》——13.Table Layout学习
  6. Android(安卓)TextView 文字居中
  7. 详解android:scaleType属性
  8. Android常用控件之悬浮窗
  9. android控件布局

随机推荐

  1. 在Eclipse中用javadoc给android工程库文
  2. Android(安卓)Bander设计与实现 - 设计篇
  3. Xamarin for VS 4.0.1.145 Stable版免费
  4. android实现上传本地图片到网络功能
  5. 9.7、Libgdx之振动器
  6. Android中RelativeLayout的使用---------
  7. android:使用SQLite的Blob储存.mp3档案
  8. Android使用newInstance()实例化fragment
  9. 深入了解android平台的jni---编译ffmpeg
  10. Android(安卓)Wake lock