AbsoluteLayout

译者署名:madgoat

译者链接:http://madgoat.cn/

版本:Android 2.2 r1

 

public class AbsoluteLayout extends ViewGroup

 

java.lang.Object

         android.view.View

                android.view.ViewGroup

                            android.widget.AbsoluteLayout

 

直接子类

         WebView

 

此类不赞成使用。

推荐使用FrameLayoutRelativeLayout或者定制的layout代替。

 

概述

        

让你指定子元素的xy精确坐标的布局。绝对布局缺乏灵活性,在没有绝对定位的情况下相比其他类型的布局更难维护。

 

公共方法       

         public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

返回一组新的基于所支持的属性集的布局参数

参数

attrs        构建layout布局参数的属性集合

返回值

一个ViewGroup.LayoutParams的实例或者它的一个子类

 

受保护方法

         protected ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)

返回一组合法的受支持的布局参数。当一个ViewGroup传递一个布局参数没有通过checkLayoutParams(android.view.ViewGroup.LayoutParams)检测的视图时,此方法被调用。此方法会返回一组新的适合当前ViewGroup的布局参数,可能从指定的一组布局参数中复制适当的属性。

参数

p      被转换成一组适合当前 ViewGroup的布局参数

返回值

an instance of ViewGroup.LayoutParams or one of its descendants

一个ViewGroup.LayoutParams的实例或者其中的一个子节点

 

protected boolean checkLayoutParams (ViewGroup.LayoutParams p)

         (译者注:检测是不是AbsoluteLayout.LayoutParams的实例,见源码:

 

protected ViewGroup.LayoutParams generateDefaultLayoutParams ()

返回一组宽度为WRAP_CONTENT,高度为WRAP_CONTENT,坐标是(00)的布局参数

返回值

一组默认的布局参数或null

 

protected void onLayout (boolean changed, int l, int t, int r, int b)

在此视图view给他的每一个子元素分配大小和位置时调用。 派生类可以重写此方法并且重新安排他们子类的布局。

参数

changed   这是当前视图view的一个新的大小或位置

l        相对于父节点的左边位置

t        相对于父节点的顶点位置

r        相对于父节点的右边位置

b       相对于父节点的底部位置

 

protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)

测量视图以确定其内容宽度和高度。此方法被measure(int, int)调用。需要被子类重写以提供对其内容准确高效的测量。

约定:当重写此方法时,你必须调用setMeasuredDimension(int, int)来保存当前视图view的宽度和高度。不成功调用此方法将会导致一个IllegalStateException异常,是由measure(int, int)抛出。所以调用父类的onMeasure(int, int)方法是必须的。

父类的实现是以背景大小为默认大小,除非MeasureSpec(测量细则)允许更大的背景。子类可以重写onMeasure(int,int)以对其内容提供更佳的尺寸。

如果此方法被重写,那么子类的责任是确认测量高度和测量宽度要大于视图view的最小宽度和最小高度(getSuggestedMinimumHeight() and getSuggestedMinimumWidth()),使用这两个方法可以取得最小宽度和最小高度。

参数

widthMeasureSpec          强加于父节点的横向空间要求。要求是使用View.MeasureSpec进行编码

heightMeasureSpec         强加于父节点的纵向空间要求。要求是使用View.MeasureSpec进行编码。

 

补充

         文件链接

                   Android的几种布局方式

                   第六讲:用户界面 View(二)

                   如何动态改变 AbsoluteLayout布局中其它布局的坐标

         示例代码

<AbsoluteLayout

android:id="@+id/AbsoluteLayout01" android:layout_height="wrap_content"

android:layout_width="fill_parent" >

<TextView

android:text="TextView01" android:id="@+id/TextView01"

android:layout_height="wrap_content" android:layout_y="10px"

android:layout_width="wrap_content" android:layout_x="110px">

</TextView>

 </AbsoluteLayout>