Android资源——布局资源
来源:互联网 发布:乐器模拟软件排行 编辑:程序博客网 时间:2024/05/02 03:09
一、概述
1、android的图形界面展示可以分为三层:activity、Window和View,而View又可以分为View(组件,如TextView)和ViewGroup(布局,如线性布局)。
2、布局是指组件在activity中的呈现方式,有两种方式创建布局:
a)利用xml文件,activity通过setContentView(R.layout.activity_main)的方式获取布局资源;
xml文件必须具备一个根元素(可以是View或者ViewGroup)和一个xmlns:android属性(属性值为android的命名空间)
layout资源xml文件语法规则如下:
<?xml version="1.0" encoding="utf-8"?> <!-- 版本声明,可以省略-->
<!-- --><ViewGroup xmlns:android=http://schemas.android.com/apk/res/android android:id="@[+][package:]id/resource_name" android:layout_height=["dimension" | "fill_parent" | "wrap_content"] android:layout_width=["dimension" | "fill_parent" | "wrap_content"] [ViewGroup-specific attributes] > <View android:id="@[+][package:]id/resource_name" android:layout_height=["dimension" | "fill_parent" | "wrap_content"] android:layout_width=["dimension" | "fill_parent" | "wrap_content"] [View-specific attributes] > <requestFocus/> </View> <ViewGroup > <View /> </ViewGroup> <include layout="@layout/layout_resource"/></ViewGroup>
b)硬代码实现;
二、布局分类
布局可以分为5种类型:线性布局(LinearLayout)、相对布局、帧布局、表格布局、绝对布局。
2.1 线性布局
线性布局是指将组件按照水平或者垂直方向放置。
常见属性:
方向控制(属性值为horizontal或者vertical)
三、实例解析
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/ImageView01" android:src="@drawable/g1" /></RelativeLayout>
属性xmlns:android表示命名空间;
参考文献:
1、《Android应用开发详解》
2、http://www.w3school.com.cn/xml/xml_syntax.asp
3、http://developer.android.com/guide/topics/resources/layout-resource.html
- Android资源——布局资源
- Android——动态加载资源布局
- Android 布局资源
- Android中的资源布局
- android 布局资源写法
- Android资源访问——字符串资源
- Android资源访问——颜色资源
- Android资源访问——尺寸资源
- Android布局类型资源简介
- Android应用资源---布局资源类型(Layout)
- Android布局类型资源(三)---menu
- Android资源布局文件命名规范
- Android应用程序资源——Animation动画资源
- Android应用程序资源——menu菜单资源
- Android应用程序资源——Drawable资源概述
- Android学习——android资源访问
- Cef应用资源布局
- API Guide:布局资源
- 箭头的重载
- HDU 4753 Fishhead’s Little Game (对抗搜索)
- Linux共享内存编程实例
- linux c学习 day03
- iOS开发之数组排序(数组中包括字典)
- Android资源——布局资源
- 简单理解transaction
- UVAlive 5792 Diccionário Portuñol (Trie)
- PID control model----PID controlor
- 开源svn地址
- 简直不能忍!org.xmlpull.v1.XmlPullParserException: expected: START_TAG 处理心得
- 何时才是个头
- 最大子段和问题小结
- Ubuntu 截图