当前位置:操作系统 > 安卓/Android >>

Android培训班(44)

<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->

layout-land和layout-port目录主要用来保存应用程序的界面布局的文件。layout-land是android应用程序界面横屏显示的布局设置;layout-port是android应用程序界面竖屏显示的布局设置。由于这两种显示,导致应用程序的显示比例不一样,因此应用程序需要根据不同的比例进行重新布局,不能简单地进行缩放显示,否则就显得界面不好使用,屏幕的空间没有最大化地利用。本来手机的屏幕就是很小的一个显示屏,如果不尽量使用,肯定就不满足用户的需求。当然两种显示的方式,也可以最大化共用相同的图片和字符串等资源。

 

在layout-land的目录下面,有如下的两个文件:

main.xml和history_item.xml

接着来查看main.xml,可以看到这个文件的内容如下:

<?xml version="1.0" encoding="utf-8"?>

这行说明XML的版本,编码的格式。

 

<!--

/*

* Copyright (C) 2008, The Android Open Source Project

*

* Licensed under the Apache License, Version 2.0 (the "License");

* you may not use this file except in compliance with the License.

* You may obtain a copy of the License at

*

* http://www.apache.org/licenses/LICENSE-2.0

*

* Unless required by applicable law or agreed to in writing, software

* distributed under the License is distributed on an "AS IS" BASIS,

* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

* See the License for the specific language governing permissions and

* limitations under the License.

*/

-->


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:background="#ff000000">

在android的应用程序界面里,主要有五种布局方式:帧布局(FrameLayout),线性布局(LinearLayout),绝对布局(AbsoluteLayout),相对布局(RelativeLayout),表格布局(TableLayout)。

在这里主要使用线性布局(LinearLayout),那么这种布局有什么样的特点呢?顾名思义,就是对界面元素进行线性的排列,比如一行有10个文本显示框,如果进行线性布局,并且是水平方向布局,那么就可以排成一行,如果显示屏不够大,后面的元素就显示不了。如果是垂直方向布局,就会每一行一个文本框的方式显示,显示为10行。在线性布局里,如果不指明布局方式,默认为水平方向排列。当然线性布局也可以嵌套显示多行子元素,但这样维护起来比较困难,应使用相对布局(RelativeLayout)来实现,这样更加方便

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,