Android绘图机制(三) ViewGroup类的延伸
来源:互联网 发布:比特币 软件 编辑:程序博客网 时间:2024/06/01 08:17
继续上一篇,先将文档中的内容补充完整,后面部分解释上一篇中的一些方法。
如果需要项实例中一样实现XML布局属性,则需要如下方式在attrs.xml文件中申明自定义属性
res/values/attrs.xml:<declare-styleable name="CustomLayoutLP"> <attr name="android:layout_gravity" /> <attr name="layout_position"> <enum name="middle" value="0" /> <enum name="left" value="1" /> <enum name="right" value="2" /> </attr></declare-styleable>
在xml布局文件中使用上述自定义布局管理器
<com.example.android.apis.view.CustomLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.example.android.apis" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 将第一个视图放到左边--> <TextView android:background="@drawable/filled_box" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_position="left" android:layout_gravity="fill_vertical|center_horizontal" android:text="l1"/> <!-- 将第二个视图叠加到左边--> <TextView android:background="@drawable/filled_box" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_position="left" android:layout_gravity="fill_vertical|center_horizontal" android:text="l2"/> <!-- 将此视图放到右边--> <TextView android:background="@drawable/filled_box" android:layout_width="wrap_content" android:layout_height="wrap_content" app:layout_position="right" android:layout_gravity="fill_vertical|center_horizontal" android:text="r1"/> <!-- 默认情况下,视图放到布局中间,使用重心垂直填充 --> <TextView android:background="@drawable/green" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="fill_vertical|center_horizontal" android:text="fill-vert"/> <!-- <span style="font-family: Arial, Helvetica, sans-serif;"> 默认情况下,视图放到布局中间,使用重心水平填充 </span><span style="font-family: Arial, Helvetica, sans-serif;">--></span> <TextView android:background="@drawable/green" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical|fill_horizontal" android:text="fill-horiz"/> <!-- <span style="font-family: Arial, Helvetica, sans-serif;">默认情况下,视图放到布局中间,使用重心左上角填充 </span><span style="font-family: Arial, Helvetica, sans-serif;">--></span> <TextView android:background="@drawable/blue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" android:text="top-left"/> <!-- <span style="font-family: Arial, Helvetica, sans-serif;">默认情况下,视图放到布局中间,使用重心重心填充 </span><span style="font-family: Arial, Helvetica, sans-serif;">--></span> <TextView android:background="@drawable/blue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="center"/> <!-- <span style="font-family: Arial, Helvetica, sans-serif;">默认情况下,视图放到布局中间,使用重心右下角填充 </span>--> <TextView android:background="@drawable/blue" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:text="bottom-right"/></com.example.android.apis.view.CustomLayout>
上篇文章中部分的方法解释:
protected void measureChildWithMargins (View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed)
方法解释:让视图其中一个子视图测量它自己,并将该视图的测量规格MeasureSpec 要求和其padding,margin值计算在内,子视图必须有一个MarginLayoutParams 值,并可通过getChildMeasureSpec()方法获取该对象。
参数解释:
方法解释:将通过public static int combineMeasuredStates (int curState, int newState) 方法返回的两个视图状态值合并。
参数解释:
返回值:表示两个状态组合后的新的状态值,整数。
public static int resolveSizeAndState (int size, int measureSpec, int childMeasuredState)
方法解释:依据测量规格MeasureSpec暴露出的约束值协调期望尺寸和视图状态的公共方法),如果约束中没有设置其他不同的值,则取期望值。返回值是一个组合整数。.如果结果值比视图的期望值小,则会将这个之分解后设置到MEASURED_SIZE_MASK 和MEASURED_STATE_TOO_SMALL 的二进制值中。
参数解释:
返回值:尺寸信息的二进制表示。总共四个:MEASURED_SIZE_MASK (提供视图实际尺寸的方法getMeasuredWidthAndState()和 getMeasuredWidthAndState()返回值得机器码值,常量值 16777215 (0x00ffffff) ) MEASURED_STATE_TOO_SMALL ( 提供视图实际尺寸的方法getMeasuredWidthAndState()和 getMeasuredWidthAndState()返回值的机器码值比视图的期望尺寸值小,常量值16777216 (0x01000000) ) MEASURED_STATE_MASK(提供视图附加状态值的方法getMeasuredWidthAndState()和 getMeasuredWidthAndState()返回值的机器码值比,常量值-16777216 (0xff000000) ) MEASURED_HEIGHT_STATE_SHIFT(MEASURED_STATE_MASK 字节偏移,使组合宽度和高度到单个整数的方法获取视图的高度字节值,如方法getMeasuredState() 和 resolveSizeAndState(int, int, int), 常量值16 (0x00000010))
- Android绘图机制(三) ViewGroup类的延伸
- Android绘图机制(三) ViewGroup类的延伸
- Android绘图机制(二) ViewGroup类
- Android绘图机制(二) ViewGroup类
- Android-ViewGroup的事件机制
- Android群英传--绘图机制与处理技巧(三)
- (七)android的绘图机制&&Drawable
- Android绘图机制(三)——自定义View的实现方式以及半弧圆新控件
- Android绘图机制(三)——自定义View的实现方式以及半弧圆新控件
- Android绘图(三)
- Android绘图机制(一) View类
- Android绘图机制(一) View类
- Android 之 ViewGroup 的事件分发机制
- android ViewGroup的事件分发机制
- android 事件分发机制(ViewGroup)
- Android ViewGroup事件分发机制(下)
- Android事件分发机制(ViewGroup篇)
- Android绘图机制(一)
- OC基础之 ---------- NSArray -------NSFileManager
- iOS动画效果和实现
- 电商搜索引擎的架构设计和性能优化
- linux yum源更新
- 一起学Git:欲学Git请先忘记
- Android绘图机制(三) ViewGroup类的延伸
- PHP和Javascript访问数组和对象时的区别
- SQL数据库的基本操作
- [leetcode 246] Strobogrammatic Number
- 一起学Git:Git文件状态
- 初识UML
- java.lang.String +concat(s1: String): String
- 原码, 反码, 补码 详解
- UVA 10082 WERTYU字符串处理