Android布局

Android的界面由布局和组件完成,组件按照布局的要求依次排列形成界面,Android的五大布局是:

【1】FrameLayout(框架布局)

         整个区域被作为一块空白区域待用,所有的组件不能指定位置,均位于这个区域的左上角,后面的组件          直接覆盖在前面的组件上面

【2】LinearLayout(线性布局)

         包括水平和垂直两种,每一行(列)只能放一个组件

         android:orientation="vertical"   垂直线性布局

         android:orientation="horizontal"  水平线性布局

         例如:用户名,用户名输入框,密码输入框,按钮按垂直线性布局排列

<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical" 
    tools:context=".MainActivity"
     >

<LinearLayout 
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" 
     android:orientation="vertical">
     
    
    <!-- 用户名 -->
     <TextView
         android:id="@+id/textUserName"
    	 android:layout_width="wrap_content"
     	 android:layout_height="wrap_content"
     	 android:text = "@string/text_username"/>
     
     <EditText
     	android:id="@+id/editUserName"             
     	android:layout_width="match_parent"
     	android:layout_height="wrap_content"
     	android:inputType="text"/>
     
     <!-- 密码 -->
     <TextView
         android:id="@+id/textPassword"
     	 android:layout_width="wrap_content"
     	 android:layout_height="wrap_content"
     	 android:text = "@string/text_password"/> 
    
    <EditText 
        android:id="@+id/editPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textPassword"/>
    
    <!-- 登录按钮 -->
    <!--android:onClick="onClick"这样写前面不用再加按钮监听器,直接点击极有反应 ,onclick为发送意图的方法名字-->
    <!-- android:text="@string/btn_login"为按钮的名字 -->
    <Button
         android:id="@+id/btnLogin"
         android:layout_width="wrap_content"
     	 android:layout_height="wrap_content"
     	 android:layout_gravity="center"
     	 android:onClick="onClick"    
     	 android:text="@string/btn_login"/>
    
     <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    
     	 
    </LinearLayout>
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</LinearLayout>

 

【3】AbsoluteLayout(绝对布局)

         android:layout_x="Xdp", android:layout_x="Xdp"指定组件的位置,即相当于给定了组件的(x,y)坐标

【4】RelativeLayout(相对布局)

         按照各个元素之间的位置完成布局,利用位置属性和各个组件的id来完成布局,

         位置属性举例:

         android:layout_toLeftOf/layout_toRightOf/layout_above/layout_below="id"---该组件位于指定组件的左边/右边/上方/下方

         android:layout_alignParentLeft/Right/Top/Bottom----该组件对齐其父组件的左边,右边,上边和下边 

【5】TableLayout(表格布局)

         一个TableLayout由很多个TableRow组成,它的子组件全部按照水平线性排列,并且宽(match parent)高(wrap parent)一致,这样所有组件就像是排列在一个表格中,单元格可以为空,但是不可以跨列

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值