Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)

线性布局:

<?xml version="1.0" encoding="utf-8"?>
<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"

    tools:context="com.example.chenshuai.test322.MainActivity"
    android:orientation="vertical"
   android:gravity="center_horizontal"

    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <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="请输入用户名"/><!--默认值-->
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="16dp">

        <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:password="true"/><!--密码输入框-->
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登陆"
            android:layout_weight="1"/><!--权重-->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:id="@+id/button2"
            android:layout_weight="1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="取消"
            android:layout_weight="1"/>

    </LinearLayout>

</LinearLayout>

表格布局

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:stretchColumns="1,2">

    <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:layout_span="2"/>

    </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:password="true"
            android:layout_span="2"/>
    </TableRow>
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登陆"
            android:layout_weight="1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注册"
            android:id="@+id/button2"
            android:layout_weight="1"/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="取消"
            android:layout_weight="1"/>
    </TableRow>

</TableLayout>

帧布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="320dp"
        android:height="320dp"
        android:layout_gravity="center"
        android:background="#f00"/><!--红色-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="280dp"
        android:height="280dp"
        android:layout_gravity="center"
        android:background="#0f0"/><!--绿色-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="240dp"
        android:height="240dp"
        android:layout_gravity="center"
        android:background="#00f"/><!--蓝色-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="200dp"
        android:height="200dp"
        android:layout_gravity="center"
        android:background="#ff0"/><!--黄色-->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width="160dp"
        android:height="160dp"
        android:layout_gravity="center"
        android:background="#f0f"/><!--紫色-->

</FrameLayout>

时间: 2024-08-05 11:14:55

Android——布局(线性布局linearLayout,表格布局TableLayout,帧布局FrameLayout)的相关文章

Android 自学之帧布局 FrameLayout

帧布局(FrameLayout)直接继承了ViewGroup组件: 帧布局容器为每一个加入其中的组件都创建了一个空白的区域,这个区域我们称之为一帧,所有每个组件都占据一帧,这些都会根据gravity属性执行自动对齐. FrameLayout的常用XML属性及相关的方法: XML属性 相关方法 说明 android:foreground setForeground(Drawable) 设置该帧布局容器的前景图像 android:foregroundGravity setForegroundGrav

Android基础入门教程——2.2.3 TableLayout(表格布局)

Android基础入门教程--2.2.3 TableLayout(表格布局) 标签(空格分隔): Android基础入门教程 本节引言: 前面我们已经学习了平时实际开发中用得较多的线性布局(LinearLayout)与相对布局(RelativeLayout), 其实学完这两个基本就够用了,笔者在实际开发中用得比较多的也是这两个,当然作为一个好学的程序猿, 都是喜欢刨根问题的,所以虽说用得不多,但是还是有必要学习一下基本的用法的,说不定哪一天能用得上呢! 你说是吧,学多点东西没什么的,又不吃亏!好

Android六大布局详解——LinearLayout(线性布局)

Android六大布局 本篇开始介绍Android的六大布局的知识,一个丰富的界面显示总是要有众多的控件来组成的,那么怎样才能让这些控件能够按你的想法进行摆放,从而自定义你所想要的用户界面呢?这就牵涉到本章将要学习的知识----六大布局.本篇将依次对LinearLayout(线性布局).RelativeLayout(相对布局).TableLayout(表格布局).FrameLayout(帧布局).GridLayout(网格布局)以及AbsoluteLayout(绝对布局)进行介绍. Linear

Android 布局详解 -三表格布局(TableLayout)以及重要属性

三表格布局(TableLayout)以及重要属性             TableLayout跟TableRow 是一组搭配应用的布局,TableLayout置底,TableRow在TableLayout的上方,而Button.TextView等控件就在TableRow之上,别的,TableLayout之上也可以零丁放控件.TableLayout是一个应用错杂的布局,最简单的用法就仅仅是拖沓控件做出个界面,但实际上,会经常在代码里应用TableLayout,例如做出表格的结果.本文首要介绍Ta

浅谈Android五大布局(二)——RelativeLayout和TableLayout

在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: RelativeLayout按照各子元素之间的位置关系完成布局.在此布局中的子元素里与位置相关的属性将生效.例如android:layout_be

Android入门开发之Linearlayout布局(七)

前言 上一节我们主要讲解了linux下的权限说明,今天我们来了解一下Android中的UI设计,聊聊android中常用的布局. android中的布局主要有六种,分别是线性布局(LinearLayout),相对布局(Relativelayout),帧布局(FrameLayout),网格布局(GridLayout)以及绝对布局(AbsoluteLayout)和表格布局(TableLayout),在这六种布局中,我们比较常用的就是线性布局和相对布局以及帧布局,所以在布局方面,我打算主要围绕这三个布

浅谈Android五大布局(二)——RelativeLayout和TableLayout【转】

http://www.cnblogs.com/wisekingokok/archive/2011/08/24/2152004.html 在浅谈Android五大布局(一)中已经描述了LinearLayout(线性布局).FrameLayout(单帧布局)和AbsoulteLayout(绝对布局)三种布局结构,剩下的两种布局RelativeLayout(相对布局)和TableLayout(表格布局)相对之前布局结构稍显复杂一点,所以这里另起篇幅进行介绍. RelativeLayout: Relat

Android精通:TableLayout布局,GridLayout网格布局,FrameLayout帧布局,AbsoluteLayout绝对布局,RelativeLayout相对布局

在Android中提供了几个常用布局: LinearLayout线性布局 RelativeLayout相对布局 FrameLayout帧布局 AbsoluteLayout绝对布局 TableLayout表格布局 GridLayout网格布局 TableLayout表格布局 TableLayout的介绍 TableLayout是将子类向分别排列成行和列的布局视图容器,TableLayout是由许多TableRow对象组成的,表格布局以行列的形式管理子控件,每一个单元是一个TableRow或者Vie

1.线性布局、相对布局、表格布局、帧布局

线性布局(Linearlayout): 有顺序.有次序.有条理的摆放着...(这是我的理解,或者说是我的表达方式) 分垂直摆放(Vertical)和平行摆放(horizontal) 相对布局(Relativelayout): 所有控件都要给id,然后通过上一个控件的id来确定下一个控件的相对位置 表格布局(Tablelayout): 很少用到 帧布局(Framelayout): 平时也很少用到,但到今天突然想到可以用来做那个置顶按钮