Android入门(十):界面的布局方式及其实际应用
关于Android界面布局,网上已经有了很多非常不错的学习资料,在这里我也不班门弄斧了,推荐两篇我认为写的不错的教程,然后再重点讲一下几种布局方式的实际应用。
教程链接:①http://www.cnblogs.com/android100/p/android-ui-detail.html
②http://blog.csdn.net/chenglong0513/article/details/7051177
第一种:LinearLayout(线性布局)
例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"> <TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/promptSex"/>
<Spinner
android:id="@+id/spnSex"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:drawSelectorOnTop="true"
android:prompt="@string/spnSexPrompt"/>
android:spinnerMode="dialog"/>
<TextView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/promptAge"/>
<EditText
android:id="@+id/edtAge"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:inputType="number"
android:text=""/>
<Button
android:id="@+id/btnDoSug"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/promptBtnDoSug"/>
<TextView
android:id="@+id/txtResult"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="@string/sugResult"/>
</LinearLayout> 因为篇幅的关系,线性布局中具体的一些属性,请读者自行查阅相关资料,毕竟属性太多了,最好的方法就是我们自己动手去实践,在实践中去掌握知识。 第二种:TableLayout(表格布局)
例:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="400dp"
android:layout_height="match_parent"
android:gravity="center_horizontal">
<TableRow>
<TextView android="name:"/>
<TextView android="sex:"/>
<TextView android="birthday:"/>
</TableRow>
<TableRow>
<TextView android="Input name:"/>
<TextView android="Input sex:"/>
<TextView android="Input birthday:"/>
</TableRow>
<Button android:txt="enter"/>
</TableLayout> 读者可以把建立项目,把上面的代码复制进去,自己看一下效果,把里面的属性可以都改一下,这样有助于你加深对组件中属性作用的认识。 RelativeLayout(相对布局)和FrameLayout(框架布局)我将会用两个实际项目的例子来进行讲解,后面两章你将看到。
Android入门(十):界面的布局方式及其实际应用的更多相关文章
- Android入门(十二)SQLite事务、升级数据库
原文链接:http://www.orlion.ga/610/ 一.事务 SQLite支持事务,看一下Android如何使用事务:比如 Book表中的数据都已经很老了,现在准备全部废弃掉替换成新数据,可 ...
- Android入门(十)SQLite创建升级数据库
原文链接:http://www.orlion.ga/603/ 一.创建数据库 Android为了让我们能够更加方便地管理数据库,专门提供了一个 SQLiteOpenHelper帮助类, 借助这个类就可 ...
- 【Android学习】四种布局方式
一.LinearLayout 线性布局,即一行展开或者一列展开,也可以嵌套,需要注意的属性如下: android:orentation //对齐方式 二.FrameLayout 帧布局,即一层层叠起 ...
- Android学习笔记④——页面的布局方式
FrameLayout(帧布局) 这个布局的特点是简单的默认把每一个视图组件都放在边框内且放在左上角,即使添加多个视图组件,他们也都是重叠在左上角,新的视图会遮挡住旧的视图.可以根据gravity来改 ...
- Android开发之5大布局方式详解
Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...
- Android入门(十八)服务
原文链接:http://www.orlion.ga/674/ 一.定义一个服务 创建一个项目ServiceDemo,然后在这个项目中新增一个名为 MyService的类,并让它继承自 Service, ...
- Android入门(十五)通知
原文链接:http://www.orlion.ga/663/ 1.通知的基本用法 创建通知的步骤,首先需要一个NotificationManager来对通知进行管理,可以调用Context的getSy ...
- Android入门(十九)WebView
原文链接:http://www.orlion.ga/676/ WebView可以在自己的应用程序中嵌入一个浏览器来展示网页. 创建一个项目WebViewDemo,修改activity_main.xml ...
- Android入门(十六)调用摄像头相册
原文链接:http://www.orlion.ga/665/ 一.调用摄像头 创建一个项目ChoosePicDemo,修改activity_main.xml: <LinearLayout xml ...
随机推荐
- ecshop 多表删除
$sql = 'DELETE O, G FROM ' . $GLOBALS['ecs']->table('delivery_order') . ' AS O, ' . $GLOBALS['ecs ...
- [Unity] Cg标准函数库
- 用C#开发ActiveX控件,并使用web调用
入职差不多两个月了,由学生慢慢向职场人做转变,也慢慢的积累知识,不断的更新自己.最近的一个项目里边,涉及到的一些问题,因为SDK提供的只是winform才能使用了,但是有需求咱们必须得完成啊,所以涉及 ...
- FindWindowEx用法
函数原型:HWND FindWindowEx(HWND hwndParent,HWND hwndChildAfter,LPCTSTR lpszClass,LPCTSTR lpszWindow): 参数 ...
- 网址前面的icon
shortcut icon和icon代码之间究竟有何区别呢.下面介绍一下 语句一:<link rel="shortcut icon" href="favicon ...
- js string 转 int Number()
var numString = '122'; var numberInt = Number(numString); var res = numberInt/2; 结果: res = 61
- [Keygen]IntelliJ IDEA 14.1.7
IntelliJ IDEA 14.1.7 Keygen package com.candy.keygen.intelliJIdea; import java.math.BigInteger; impo ...
- Python自动化之django的ORM操作——Python源码
""" The main QuerySet implementation. This provides the public API for the ORM. " ...
- servlet 访问流程
- Python多进程(2)——mmap模块与mmap对象
本文介绍Python mmap模块与mmap对象的用法. mmap 模块提供“内存映射的文件对象”,mmap 对象可以用在使用 plain string 的地方,mmap 对象和 plain stri ...