始创于2000年 股票代码:831685
咨询热线:0371-60135900 注册有礼 登录
  • 挂牌上市企业
  • 60秒人工响应
  • 99.99%连通率
  • 7*24h人工
  • 故障100倍补偿
您的位置: 网站首页 > 帮助中心>文章内容

使用线性布局(LinearLayout)来布局屏幕

发布时间:  2012/8/27 17:21:16

第1章 UI布局开发实例集锦

外观向来是工业产品的设计核心,是激发用户购买欲望的主要因素之一。本章讲的UI布局指的是手机界面布局,一款手机的屏幕界面效果是吸引用户购买的重要元素之一,因为消费者更倾向于选择界面美观的产品。在设计优美的界面之前,一定要先对屏幕进行布局。本章将使用具体实例的实现过程介绍在Android系统中规划UI界面的方法。

实例001:使用线性布局(LinearLayout)来布局屏幕

源码路径:daima\001

知识点介绍

在Android布局中,需要了解视图容器组件-ViewGroup的概念,使用视图容器组件ViewGroup的语法格式如下:
 

  1. ndroid.view.Viewgroup 

ViewGroup的功能是包含并管理下级系列的Views和其他ViewGroup,是一个布局的基类。类ViewGroup好像一个View容器,负责对添加进来的View进行布局处理。一个ViewGroup可以添加到另一个ViewGroup中去。这是因为ViewGroup也继承于View.Viewgroup类,是其他容器类的基类。它们之间的关系如图1-1所示。
 

 
图1-1  各个类的继承关系

我们知道,一个Android程序是由一个或多个Activity组成的,每个Activity是一个UI容器,Activity本身不在用户界面中显示出来。在Android中,类View起了一个非常重要的作用,View是一个最基本的UI类,几乎所有的UI组件都是继承于View而实现的。

使用View的语法格式如下所示。
 

  1. android.view.View 

线性布局即LinearLayout布局,是Android屏幕中常用的布局方式之一,功能是垂直地或水平地显示ViewGroup的子视图(View)元素。

具体实现

使用Eclipse创建一个名为"001"的Android工程。

编写布局文件"res/layour/main.xml",代码如下所示。

  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   
  3.               android:layout_width="fill_parent"   
  4.               android:layout_height="fill_parent"   
  5.               android:orientation="horizontal"> 
  6.     <Button android:id="@+id/button1"   
  7.             android:layout_width="wrap_content"   
  8.             android:layout_height="wrap_content"              
  9.             android:text="第一个按钮"   
  10.             android:layout_weight="1"   
  11.             />   
  12.     <Button android:id="@+id/button2"   
  13.     android:layout_width="wrap_content"   
  14.     android:layout_height="wrap_content"   
  15.     android:text="第二个按钮"   
  16.     android:layout_weight="1"   
  17.     />   
  18.     <Button android:id="@+id/button3"   
  19.     android:layout_width="wrap_content"   
  20.     android:layout_height="wrap_content"   
  21.     android:text="第三个按钮"   
  22.     android:layout_weight="1"   
  23.     />   
  24.     <Button android:id="@+id/button4"   
  25.     android:layout_width="wrap_content"   
  26.     android:layout_height="wrap_content"   
  27.     android:text="第四个按钮"   
  28.     android:layout_weight="1"   
  29.     />   
  30.     <Button android:id="@+id/button5"   
  31.     android:layout_width="wrap_content"   
  32.     android:layout_height="wrap_content"   
  33.     android:text="第五个按钮"   
  34.     android:layout_weight="1"   
  35.     />   
  36. </LinearLayout> 

在上述代码中,在根LinearLayout视图组(ViewGroup)中包含了5个按钮(Button),它的子元素是以线性方式水平布局的。上述代码的运行效果如图1-2所示。
 


本文出自:亿恩科技【www.enkj.com】

服务器租用/服务器托管中国五强!虚拟主机域名注册顶级提供商!15年品质保障!--亿恩科技[ENKJ.COM]

  • 您可能在找
  • 亿恩北京公司:
  • 经营性ICP/ISP证:京B2-20150015
  • 亿恩郑州公司:
  • 经营性ICP/ISP/IDC证:豫B1.B2-20060070
  • 亿恩南昌公司:
  • 经营性ICP/ISP证:赣B2-20080012
  • 服务器/云主机 24小时售后服务电话:0371-60135900
  • 虚拟主机/智能建站 24小时售后服务电话:0371-60135900
  • 专注服务器托管17年
    扫扫关注-微信公众号
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 亿恩科技 版权所有  地址:郑州市高新区翠竹街1号总部企业基地亿恩大厦  法律顾问:河南亚太人律师事务所郝建锋、杜慧月律师   京公网安备41019702002023号
      1
     
     
     
     

    0371-60135900
    7*24小时客服服务热线