Android_布局

Android提供了5种类型的布局类型:

 1:LinearLayout(线性布局)流式布局

 Tip:下一个控件的坐标原点由上一个控件来决定,你可以沿水平方向或者垂直方向上来排列你的控件。 

 

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.lizelu.userinterfacedemo.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--垂直线性布局方式-->
<LinearLayout
android:layout_width="pt"
android:layout_height="match_parent"
android:background="#ff"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="pt"
android:background="#ff"
android:orientation="horizontal">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
View Code

 

 2:RelativeLayout(相对布局)Activity默认布局方式

  Tip:相对布局可以根据已经固定的控件来确定其他新加控件的位置。

<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"
tools:context="com.example.lizelu.userinterfacedemo.MainActivity">
<Button
android:id="@+id/button_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="center"/>
<Button
android:id="@+id/button_above"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button_center"
android:layout_centerInParent="true"
android:text="above"/>
<Button
android:id="@+id/button_below"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button_center"
android:layout_centerInParent="true"
android:text="below"/>
<Button
android:id="@+id/button_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/button_center"
android:layout_centerVertical="true"
android:text="left"/>
<Button
android:id="@+id/button_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/button_center"
android:layout_centerVertical="true"
android:text="right"/>
</RelativeLayout>
View Code

 3:TableLayout(表格布局)

  Tip:表格布局中,整个页面就相当于一张大的表格,控件就放在每个Cell中

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户名:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="密 码:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码"
android:inputType="textPassword"/>
</TableRow>
<TableRow>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="登录"
android:layout_span=""/>
</TableRow>
</TableLayout>
View Code

 4:AbsoluteLayout(绝对布局)

  Tip:指定组件的左上角绝对坐标来指定组件的布局

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="按钮1"
    android:layout_x="0px" android:layout_y="0px" />
  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="按钮2"
    android:layout_x="20px" android:layout_y="20px" />
  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="按钮3"
    android:layout_x="40px" android:layout_y="40px" />
  <Button android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="按钮4"
    android:layout_x="60px" android:layout_y="60px" />
</AbsoluteLayout>
View Code

 5:FrameLayout(单帧布局)

  Tip:FrameLayout中的Frame和iOS中的Frame不是一个概念,在iOS中的Frame你可以指定任意的坐标,而这个坐标点时相对于父视图的。FrameLayout中的Frame的坐标原点是屏幕的左上角,位置固定,你只需为控件指定大小即可

<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.lizelu.userinterfacedemo.MainActivity">
<FrameLayout
android:layout_width="pt"
android:layout_height="pt"
android:background="#ff">
<FrameLayout
android:layout_width="pt"
android:layout_height="pt"
android:background="#ff">
</FrameLayout>
<FrameLayout
android:layout_width="pt"
android:layout_height="pt"
android:background="#ff">
</FrameLayout>
<FrameLayout
android:layout_width="pt"
android:layout_height="pt"
android:background="#ffff">
</FrameLayout>
<FrameLayout
android:layout_width="pt"
android:layout_height="pt"
android:background="#">
</FrameLayout>
</FrameLayout>
</RelativeLayout>
View Code

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

过客非归

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值