【Android快速入门3】布局简介及例子

目前自学到布局部分,下面演示了不同布局的基本训练,涵盖的内容还是不错的,而且简单易懂,分享给大家。

1.LinearLayout流式布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:text="开始"
        />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|left"
        android:text="返回"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="结束"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="3"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="new"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:visibility="invisible"
            android:text="newc"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="news"
            />
    </LinearLayout>

</LinearLayout>

2.RelativeLayout相对布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="Fight"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="L_f"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:text="R_f"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        android:text="Run"
        />
    <Button
        android:id="@+id/bom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Boom!"
        />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/bom"
        android:layout_alignBaseline="@+id/bom"
        android:text="左"
        />
     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/bom"
        android:layout_alignBaseline="@+id/bom"
        android:text="右"
        />
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
          android:layout_above="@+id/bom"
          android:layout_centerHorizontal="true"
        android:text="上"
        />
       <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
          android:layout_below="@+id/bom"
          android:layout_centerHorizontal="true"
        android:text="下"
        />

</RelativeLayout>

3.FrameLayout帧布局

<?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" >
    <Button
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        />
    <Button
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center"
        />
    <Button
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        />

</FrameLayout>

4.其他不常用布局,比如绝对布局,表格布局

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="150dp"
        android:layout_y="160dp"
        android:text="kakka"
        />

</AbsoluteLayout>
<?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:shrinkColumns="0"
    android:collapseColumns="0">
    <TableRow
        android:layout_height="wrap_content">
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L1,C0"
                />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L1,C1"
                />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L1,C3"
                />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L1,C4"
                />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L1,C5"
                />
    </TableRow>
    <TableRow
        android:layout_width="wrap_content"
        >
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="L2,C0"
            />
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="3"
            android:layout_span="2"
            android:text="L2,C1"
            />
    </TableRow>

</TableLayout>

【Android快速入门3】布局简介及例子,布布扣,bubuko.com

时间: 2024-08-02 10:55:12

【Android快速入门3】布局简介及例子的相关文章

Hello, Android 快速入门

Hello, Android Android 开发与 Xamarin 简介 在这两节指南中,我们将 (使用 Xamarin Studio或 Visual Studio)建立我们的第一个 Xamarin.Android 应用程序 并理解使用Xamarin 开发Android 应用程序的基本原理的.在这个系列,我们将介绍有关工具的使用. Android开发相关的概念.构建和部署 Xamarin.Android 的应用程序所需的步骤. Hello, Android 快速入门 在本演练中,我们要创建一个

Bmob移动后端云服务平台--Android从零开始--(二)android快速入门

Bmob移动后端云服务平台--Android从零开始--(二)android快速入门 上一篇博文我们简单介绍何为Bmob移动后端服务平台,以及其相关功能和优势.本文将利用Bmob快速实现简单例子,进一步了解它的强大之处. 一.准备工作 1.注册Bmob账号 在网址栏输入www.bmob.cn或者在百度输入Bmob进行搜索,打开Bmob官网后,点击右上角的"注册",在跳转页面填入你的姓名.邮箱.设置密码,确认后到你的邮箱激活Bmob账户,你就可以用Bmob轻松开发应用了. 2.网站后台创

【Android快速入门1】目录结构及adb命令(以API19为例)

目录结构 src: 存放java代码gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的idproject.properties: 指定当前工程采用的开发工具包的版本libs: 当前工程所依赖的jar包.assets: 放置一些程序所需要的媒体文件.bin: 工程的编译目录. 存放一些编译时产生的临时文件和当前工程的.apk文件. res(resources): 资源文件. drawable: 存放程序所用的图片. layout: 存放android的布局文件. fragm

【Android快速入门】目录结构及adb命令【附Android拨号器的实现,自作】

目录结构 src: 存放java代码 gen: 存放自动生成文件的. R.java 存放res文件夹下对应资源的id project.properties: 指定当前工程采用的开发工具包的版本 libs: 当前工程所依赖的jar包. assets: 放置一些程序所需要的媒体文件. bin: 工程的编译目录. 存放一些编译时产生的临时文件和当前工程的.apk文件. res(resources): 资源文件. drawable: 存放程序所用的图片. layout: 存放android的布局文件.

【Android快速入门2】拨号器的实现

拨号器是个很简单的布局,用来做Android的入门最好不过. 本程序给予Android API19编译实现,因此是新版布局.不习惯的请注意. 截图下次我有空补上. 1.Java主程序: public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setC

Android基础篇之Android快速入门--你必须要知道的基础

Android快速入门 1. 搭建开发环境 >解压压缩文件,得到:①Android SDK   (类似于JDK)② Eclipse  ③ADT >配置两个path环境变量:D:\adt-bundle-windows-x86\sdk\platform-tools:D:\adt-bundle-windows-x86\sdk\tools >配置基本的Eclipse的设置: 调整字体大小,字符集,配置android sdk的位置 >创建模拟器: 2. 创建第一个Android项目: Hel

Xamarin.Android快速入门

一.准备工作 1.创建一个空的解决方案,并命名为Phoneword 2.右击解决方案 新建->新建项目 并命名为Phoneword_Droid 二.界面 1.打开Resources文件夹->layout文件夹双击打开Main.axml 2.然后将会出现下面的界面 3.接着我们选择这个Button并删除(按下Delete),并从左边的工具箱中拖拽一个 Text(Large) 控件到该界面中,如下所示: 4.同时还要通过属性窗口修改Text的值: 5.紧接着拖拽一个Plain Text控件到之前的

Android快速入门教程总结帖

从3月份底开始,到5月15号,刚好差不多1个半月,小巫受CSDN学院邀请成为在线讲师,录制了第一门课程,关于Android入门的.从一开始录制这个课程非常困难,不停的NG,毕竟有点感觉一个人对着屏幕说话有点傻愣,如果别人不知道的话,确实以为你疯了,所以小巫花了一个半月的下班晚上时间和周末的时间,紧闭房门,与世隔绝,才勉勉强强把整套课程录制完.由于初期订的的价格也许太高,网上免费教学资源太多,所以这套课程不受欢迎是必然的了.不管怎样,关于学习这件事,方法和思路很重要,经验可以从书或者大牛身上获得,

CSS快速入门-前端布局1(抽屉)

一.效果图 前面对CSS基础知识有了一定的了解,是时候开始实战了!以下我对抽屉(https://dig.chouti.com/)主页进行模拟布局. 官方网站效果图: 模拟网站图: 二.实现步骤 1.整体布局(header.body.footer) 抽屉的首页主要分为三块:头部.网页内容.底部内容. 2.header实现 header由logo.内容菜单.登录菜单.搜索框四部分组成. 代码架构为: body{ margin:0px; background-color:#ededed; } ul{