Android布局揭秘
前言
今天把对于布局的一些理解写下来,主要内容包括控件的属性的继承关系,控件与容器的属性的关系,以及各种类的属性的使用。
控件的属性种类
通常意义上讲,我们在对一个控件进行属性赋值的时候大体上有种类型的属性,一种为layout_开头的属性,一种为不是以layout_开头的属性,下面以TextView为例进行说明,如下所示
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello_world" /> </RelativeLayout>
我为TextView设置了三个属性layout_width、layout_height以及text,可以看到这三个属性中layout_width、layout_height属性为layout_开头而text没有以Layout_开头。
以layout_开头的属性为从容器中继承的属性,在这个例子里面即是从RelativeLayout中继承来的,TextView本身并没有此属性。而text则是TextView自身拥有的属性。
为了说明layout属性为容器属性,我做了下面的例子,把TextView分别放置到RelativeLayout和LinearLayout中,然后对TextView设置layout_centerInParent属性,之所有选择这个属性,是因为这个属性为RelativeLayout所有而LinearLayout没有,实验代码如下
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="hello_world" />
</RelativeLayout> <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="hello world2" />
</LinearLayout>
如上进行设置之后会发现,编辑器提示“Invalid layout param in a LinearLayout: layout_centerInParent”,如下所示
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAqkAAAC4CAIAAABPUeKHAAAgAElEQVR4nO2dzYss13n/638wMSKQf2BANs7FXtTmBvkvMPQlIEFWQ22ShbE3t/GiW1Yul0QRqUUqEyXuoI0uDcUIrwqvZqjhxshYIja0atOyxmMluT+mQZgfXniVJ4t6Oy/POXWquqq6pvv74UHql1PnPKdqbn/Pc149IiKiR+/T73//e/t/SWKzfhpe3ZOG9vlm/XS90dMp/PGPf2xMA3oh9Rdx8kB9yGIv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Da39wVr8tq79rvWkQZ+osdAJb0/Y/37258zPMHAAAiaq39XE+/pO3KZj/3V6FbS2Hi2k9Exfp+Sekbgn4aWPvzSXOKlIpT6Jnp9H33+bsWQdXQANNXoTQIlAkBpNyHYrBDzUdeLJA9q2cv5hszdNlyEQAAjpJ22s/s18ts2rtZC185dhE8BO1XsQX9lsF4qbecSVCooJhDnCnp1XV95rF28dvzdFdmUginvDRfy8GhFo1FqM4YliBKtdAbIpIn0Yus3vxAQFrob5nwCAAAJw7O8ulOeNEQ9AOJXXqObXcBAGACQPu7kl1iylgr9J58AAAABwHaD8ZB2s8HAADAAYH2gyHRZwwg9AcAgEMD7QcAAABOC2g/AAAAcFpA+wEAAIDTAtoPAAAAnBbQfgAAAOC0gPYDAAAAp0UX7Rd39rVt2Svu7dt0mg+0HwAAABiH1tovH9ajHN1TcxU6CL4AtB8AAAAYh5baf38VqqH+Zq0F/9xpfw1A+wEAAIBx6GG8XzrDl4jur8Lwqq0f0H4AAABgHPbW/ntW+p3O7RWB9gMAAADjsKf28x3+4dW9MB/QqSUA7QcAAADGYR/t54f1r8KnYRjWks9MEWCA9gMAAADj0Fn7jfP5rkIt1r+/CrHGDwAAAJgGnbT//io0T+TfrJ8+Veb6bdbqJxrQfgAAAGAc2mt/ru2WPny9kx9xPwAAADAZ/g+hJJ7KkcOmaAAAAABJRU5ErkJggg==" alt="" />
通过此实验可以得出结论,layout开头的属性并非TextView所拥有,而是继承的容器中关于布局的属性,继而推而广之,可以得出结论,控件的属性可以分为自身属性和容器中的布局属性。下面就通过TextView和各个布局容器一起来详细分析下属性。
LinearLayout和TextView
这一小节主要介绍下LinearLayout和TextView的属性,先来看下TextView的属性,及属性继承关系,
下面为TextView自身所拥有的属性
XML Attributes | |||||||||
---|---|---|---|---|---|---|---|---|---|
Attribute Name | |||||||||
android:autoLink | |||||||||
android:autoText | |||||||||
android:bufferType | |||||||||
android:capitalize | |||||||||
android:cursorVisible | |||||||||
android:digits | |||||||||
android:drawableBottom | |||||||||
android:drawableEnd | |||||||||
android:drawableLeft | |||||||||
android:drawablePadding | |||||||||
android:drawableRight | |||||||||
android:drawableStart | |||||||||
android:drawableTop | |||||||||
android:editable | |||||||||
android:editorExtras | |||||||||
android:ellipsize | |||||||||
android:ems | |||||||||
android:fontFamily | |||||||||
android:freezesText | |||||||||
android:gravity | |||||||||
android:height | |||||||||
android:hint | |||||||||
android:imeActionId | |||||||||
android:imeActionLabel | |||||||||
android:imeOptions | |||||||||
android:includeFontPadding | |||||||||
android:inputMethod | |||||||||
android:inputType | |||||||||
android:lineSpacingExtra | |||||||||
android:lineSpacingMultiplier | |||||||||
android:lines | |||||||||
android:linksClickable | |||||||||
android:marqueeRepeatLimit | |||||||||
android:maxEms | |||||||||
android:maxHeight | |||||||||
android:maxLength | |||||||||
android:maxLines | |||||||||
android:maxWidth | |||||||||
android:minEms | |||||||||
android:minHeight | |||||||||
android:minLines | |||||||||
android:minWidth | |||||||||
android:numeric | |||||||||
android:password | |||||||||
android:phoneNumber | |||||||||
android:privateImeOptions | |||||||||
android:scrollHorizontally | |||||||||
android:selectAllOnFocus | |||||||||
android:shadowColor | |||||||||
android:shadowDx | |||||||||
android:shadowDy | |||||||||
android:shadowRadius | |||||||||
android:singleLine | |||||||||
android:text | |||||||||
android:textAllCaps | |||||||||
android:textAppearance | |||||||||
android:textColor | |||||||||
android:textColorHighlight | |||||||||
android:textColorHint | |||||||||
android:textColorLink | |||||||||
android:textIsSelectable | |||||||||
android:textScaleX | |||||||||
android:textSize | |||||||||
android:textStyle | |||||||||
android:typeface | |||||||||
android:width |
TextView继承属性
From class android.view.View
Attribute Name |
android:accessibilityLiveRegion |
android:alpha |
android:background |
android:clickable |
android:contentDescription |
android:drawingCacheQuality |
android:duplicateParentState |
android:fadeScrollbars |
android:fadingEdgeLength |
android:filterTouchesWhenObscured |
android:fitsSystemWindows |
android:focusable |
android:focusableInTouchMode |
android:hapticFeedbackEnabled |
android:id |
android:importantForAccessibility |
android:isScrollContainer |
android:keepScreenOn |
android:layerType |
android:layoutDirection |
android:longClickable |
android:minHeight |
android:minWidth |
android:nextFocusDown |
android:nextFocusForward |
android:nextFocusLeft |
android:nextFocusRight |
android:nextFocusUp |
android:onClick |
android:padding |
android:paddingBottom |
android:paddingEnd |
android:paddingLeft |
android:paddingRight |
android:paddingStart |
android:paddingTop |
android:requiresFadingEdge |
android:rotation |
android:rotationX |
android:rotationY |
android:saveEnabled |
android:scaleX |
android:scaleY |
android:scrollX |
android:scrollY |
android:scrollbarAlwaysDrawHorizontalTrack |
android:scrollbarAlwaysDrawVerticalTrack |
android:scrollbarDefaultDelayBeforeFade |
android:scrollbarFadeDuration |
android:scrollbarSize |
android:scrollbarStyle |
android:scrollbarThumbHorizontal |
android:scrollbarThumbVertical |
android:scrollbarTrackHorizontal |
android:scrollbarTrackVertical |
android:scrollbars |
android:soundEffectsEnabled |
android:tag |
android:textAlignment |
android:textDirection |
android:transformPivotX |
android:transformPivotY |
android:translationX |
android:translationY |
android:visibility |
也就是说这两部分加起来就是TextView的全部属性,然而我们在XML编辑器中编辑代码的时候会发现,除了以上属性外还有很多以layout开头的属性可以设置,这些就是容器的属性,下面以LinearLayout为例,实验场景如下
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world2" />
</LinearLayout>
下面我们就看下LinearLayout的布局属性,通过LinearLayout.LayoutParams类来体现
通过帮助文档可以看到,其自身属性为以下内容
XML Attributes | |||||||||
---|---|---|---|---|---|---|---|---|---|
Attribute Name | |||||||||
android:layout_gravity | |||||||||
android:layout_weight |
还有继承了两类属性,android.view.ViewGroup.MarginLayoutParams
Attribute Name |
android:layout_marginBottom |
android:layout_marginEnd |
android:layout_marginLeft |
android:layout_marginRight |
android:layout_marginStart |
android:layout_marginTop |
和android.view.ViewGroup.LayoutParams
Attribute Name | Related Method | Description |
android:layout_height | Specifies the basic height of the view. | |
android:layout_width | Specifies the basic width of the view. |
以上所有属性就是布局控件提供的布局属性
所以,TextView可以设置的属性即为自身属性和以上的布局属性。
后记
以上我们通过LinearLayout和TextView的组合分析了Android中布局的属性使用情况,通过以上的分析使得我们能够了解到控件属性的由来,这样就可以更加随心所欲的进行界面布局了。
同样的道理,可以去分析RelativeLayout、TableLayout等等。
原文地址:http://www.cnblogs.com/luoaz/p/3947100.html
Android布局揭秘的更多相关文章
- 【转】在Android布局中使用include和merge标签
内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...
- Android成长日记-Android布局优化
Android常用布局 1. LinearLayout(线性布局) 2. RelativeLayout(相对布局) 3. TableLayout(表格布局) 4. AbsoluteLayou(绝对布局 ...
- 【转】Android布局优化之ViewStub
ViewStub是Android布局优化中一个很不错的标签/控件,直接继承自View.虽然Android开发人员基本上都听说过,但是真正用的可能不多. ViewStub可以理解成一个非常轻量级的Vie ...
- Android 布局之LinearLayout
Android 布局之LinearLayout 1 LinearLayout简介 LinearLayout是线程布局.它包括2个方向(android:orientation):“水平”(horizon ...
- Android 布局之RelativeLayout
Android 布局之RelativeLayout 1 RelativeLayout简介 RelativeLayout是相对布局. RelativeLayout布局属性 1.1 与parent相对的属 ...
- Android 布局之TableLayout
Android 布局之TableLayout 1 TableLayout简介 TableLayout是表格布局.TableLayout 可设置的属性包括全局属性及单元格属性. 1.1 全局属性 有以下 ...
- Android 布局之FrameLayout
Android 布局之FrameLayout 1 FrameLayout简介 对于FrameLayout,官方介绍是:FrameLayout is designed to block out an a ...
- Android 布局之GridLayout
Android 布局之GridLayout 1 GridLayout简介 GridLayout是Android4.0新提供的网格矩阵形式的布局控件. GridLayout的继承关系如下:java.la ...
- Xamarin Android布局文件没有智能提示
Xamarin Android布局文件没有智能提示 在Visual Studio 2015中,Android项目的Main.axml文件没有智能提示,不便于布局文件的编写.解决办法:(1)从Xamar ...
随机推荐
- C#操作XML(带命名空间)
之前文章讲述了使用c# xpath如何操作xml文件,在实际开发项目中,遇到的很多xml文件都是带有命名空间的,如果还是用之前的代码获取,那将获取到null.本文讲解操作代码有命名空间的Xml文件,以 ...
- Sql 使用备份还是使用脚本
对sql使用并不熟悉,但是通过项目接触总结出的经验 什么样的场景下选择使用脚本或者备份: 1:当需要创建相关的库的时候使用脚本 2:当需要还原至某个时间点的状态的或者前进至某个版本的数据库的时候就使用 ...
- A Multipart Series on Grids in ASP.NET MVC
A Multipart Series on Grids in ASP.NET MVC Displaying a grid of data is one of the most common tasks ...
- [Java] HashMap遍历的两种方式
Java中HashMap遍历的两种方式原文地址: http://www.javaweb.cc/language/java/032291.shtml第一种: Map map = new HashMap( ...
- DPKG命令与软件安装、APT
====Linux软件包==== Linux系统中,软件通常以源代码或者预编译包的形式提供. 软件的源代码通常需要编译为二进制代码才可使用,安装比较耗时.用户可以自行调节编译选项,决定需要的功能或组件 ...
- iOS UINavigationController 详解
developer.apple.com/cn/ 导航条 UINavigationBar继承UIView 导航控制器 UINavigationController (压栈,出栈) ...
- uva 101 POJ 1208 The Blocks Problem 木块问题 vector模拟
挺水的模拟题,刚开始题目看错了,poj竟然过了...无奈.uva果断wa了 搞清题目意思后改了一下,过了uva. 题目要求模拟木块移动: 有n(0<n<25)快block,有5种操作: m ...
- [课程相关]附加题——stack的理解
一.stack的三种解释 stack有三种解释,我个人理解如下. 1.用户自定义的stack 用户自定义的stack就是一般意义上的后进先出队列,从名字上就能理解了,stack由下向上增长,有一个顶指 ...
- PHP中正则替换函数preg_replace用法笔记
今天应老板的需求,需要将不是我们的页面修改一个链接,用js+iframe应该也能实现,但是我想尝试一下php实现方法. 首先你得先把别人的页面download到你的php中,实现方法可以用curl, ...
- JQ笔记
参数形式$("input:text",document.forms[0])选择form[0]所有input=text$("<p>123</p>&q ...