Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5709307
  • 博文数量: 409
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 8273
  • 用 户 组: 普通用户
  • 注册时间: 2013-10-23 19:15
个人简介

qq:78080458 学习交流群:150633458

文章分类

全部博文(409)

文章存档

2019年(127)

2018年(130)

2016年(20)

2015年(60)

2014年(41)

2013年(31)

分类: Android平台

2013-12-18 08:33:04

android布局方式—Linearlayout

线性布局是最常见的布局方式,它可以分为水平布局和垂直布局。

Androidlayout_width宽度设置,有两种常见的值fill_parent填充父容器,wrap_content包裹内容

Androidlayout_height设置高度,其值和layout_width一样

androidorientation来设置线性布局的方向

Androidgravity设置对齐方式,如果没有子控件则设置里面文字的对齐方式,如果有子控件则设置子控件的对齐方式,可以取三种值rightcenterlefttopbottom

坐标的单位是px,高度和宽度的单位是dp

Androidbackground设置背景颜色

Androidlayout_weight设置控件的相对大小,每个控件大小是在所有控件大小之和所占的比例,如果两个控件的layout_weight都为1,那么他们就各占50%。如果layout_weight0,那么就是原始大小,其他控件的大小为除去这个控件后的总和所占的比例

Linearlayout可以嵌套使用

<LinearLayout xmlns:android=""

    xmlns:tools=""

    android:layout_width="match_parent"

    android:layout_height="match_parent"

android:orientation="vertical"

>

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:textSize="20sp"   

       android:textColor="#00ff00"

        android:text="@string/hello_android" />

 

android:layout_width="match_parent"

       android:layout_height="match_parent"

android:orientation="horizontal"

>

       <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"       

        android:id="@+id/btn1"

        android:text="click me1"

        />

           <Button

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"       

        android:id="@+id/btn2"

        android:text="click me2"

        />

LinearLayout>

</LinearLayout >

 

android布局方式—AbsolutelyLayout

absolutelylayout绝对布局,指定xy坐标,一般不推荐

androidlayout_x指定x坐标

androidlayout_y指定y坐标

android:layout_width="match_parent"

       android:layout_height="match_parent"

android:orientation="horizontal"

>

       <Button

        android:layout_x="10px"

        android:layout_y="10px"       

        android:id="@+id/btn1"

        android:text="click me1"

        />

AbsolutelyLayout>

 

android布局方式—FrameLayout

FrameLayout层叠样式,所有添加的控件都叠加在一起,最先添加的再最下面,最后添加的再最上面。层叠的样式用gravity来设置

android:layout_width="match_parent"

       android:layout_height="match_parent"

android:orientation="horizontal"

>

       <Button

        android:layout_height="wrap_content"

        android:layout_y="fill_parent"       

        android:id="@+id/btn1"

        android:text="click me1"

        />

        <Button

        android:layout_height="wrap_content"

        android:layout_y="fill_parent"       

        android:id="@+id/btn2"

        android:text="click me1"

       android:gravity = “left”

        />

FrameLayout>

 

android布局方式—RelativeLayout

相对布局,针对指定的控件来设置布局,有4个属性可以设置:androidlayout_above当前控件在指定控件的上方,Android:layout_bellow当前控件在指定控件的下方,Android:layout_toLeftOf当前控件在指定控件的左边,Android:layout_toRightOf当前控件在指定控件的右边

布局的对齐方式有:Android:layout_alignBottom与指定控件底部对齐,Android:layout_alignTop与指定控件的顶部对齐,Android:layout_alignLeft与指定控件的左边对齐,Android:layout_alignRight与指定控件的右边对齐。

控件与父容器的对齐方式androidlayout_alignParentLeft,如果为True,该控件位于容器的左侧;androidlayout_alignParentRight,如果为True,该控件位于容器的右侧;androidlayout_alignParentTop,如果为True,该控件位于容器的顶部;androidlayout_alignParentBottom,如果为True,该控件位于容器的底部;androidlayout_centerHorientatl,如果为True,该控件位于容器的水平中间;androidlayout_centerVertical,如果为True,该控件位于容器的垂直中间;androidlayout_centerInParent,如果为True,该控件位于容器的水平和垂直中间

< RelativeLayout

android:layout_width="match_parent"

       android:layout_height="match_parent"

android:orientation="horizontal"

>

       <Button

        android:layout_height="wrap_content"

        android:layout_y="fill_parent"       

        android:id="@+id/btn1"

        android:text="click me1"

        />

        <Button

        android:layout_height="wrap_content"

        android:layout_y="fill_parent"       

        android:id="@+id/btn2"

        android:text="click me1"

       android:gravity = “left”

        />

RelativeLayout >

android布局方式—TableLayout

通过表格的形式来进行布局,和html一样。Tablerow表示行。AndroidcollapseColumns隐藏指定的列,从0号开始;AndroidshrinkColumns收缩指定的列以适合屏幕,AndroidstrecthColumns尽量把指定的列填充空白;Androidlayout_column控件在tablerow中所处的列;Androidlayout_span该控件所跨越的列数

< TableLayout

android:layout_width="match_parent"

       android:layout_height="match_parent"

AndroidcollapseColumns = “0,1”隐藏第0列和第1

>

       <Button 

        android:id="@+id/btn00"

        android:text="click me1"

        />

        <Button

        android:id="@+id/btn01"

        android:text="click me1"

        />

       <Button

        android:id="@+id/btn02"

        android:text="click me1"

        />

 

   

       <Button 

        android:id="@+id/btn10"

        android:text="click me1"

        />

        <Button

        android:id="@+id/btn12"

        android:text="click me1"

Androidlayout_column = “2”  放在第2行第2

        />

   

TableLayout >

阅读(17485) | 评论(0) | 转发(4) |
给主人留下些什么吧!~~