?
本文檔使用 PHP中文網(wǎng)手冊(cè) 發(fā)布
AbsoluteLayout
版本:Android 2.2 r1
?
public class AbsoluteLayout extends ViewGroup
?
java.lang.Object
???????? android.view.View
? ???? ???????? android.view.ViewGroup
??????????????????????????? android.widget.AbsoluteLayout
?
直接子類(lèi)
???????? WebView
?
此類(lèi)不贊成使用。
推薦使用FrameLayout
,RelativeLayout
或者定制的layout代替。
?
概述
????????
讓你指定子元素的xy精確坐標(biāo)的布局。絕對(duì)布局缺乏靈活性,在沒(méi)有絕對(duì)定位的情況下相比其他類(lèi)型的布局更難維護(hù)。
?
公共方法???????
???????? public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)
返回一組新的基于所支持的屬性集的布局參數(shù)
參數(shù)
attrs ?????? 構(gòu)建layout布局參數(shù)的屬性集合
返回值
一個(gè)ViewGroup.LayoutParams的實(shí)例或者它的一個(gè)子類(lèi)
?
受保護(hù)方法
???????? protected ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams p)
返回一組合法的受支持的布局參數(shù)。當(dāng)一個(gè)ViewGroup傳遞一個(gè)布局參數(shù)沒(méi)有通過(guò)checkLayoutParams(android.view.ViewGroup.LayoutParams)檢測(cè)的視圖時(shí),此方法被調(diào)用。此方法會(huì)返回一組新的適合當(dāng)前ViewGroup的布局參數(shù),可能從指定的一組布局參數(shù)中復(fù)制適當(dāng)?shù)膶傩浴?/span>
參數(shù)
p ???? 被轉(zhuǎn)換成一組適合當(dāng)前 ViewGroup的布局參數(shù)
返回值
an instance of ViewGroup.LayoutParams or one of its descendants
一個(gè)ViewGroup.LayoutParams的實(shí)例或者其中的一個(gè)子節(jié)點(diǎn)
?
protected boolean checkLayoutParams (ViewGroup.LayoutParams p)
???????? (譯者注:檢測(cè)是不是AbsoluteLayout.LayoutParams的實(shí)例,見(jiàn)源碼:
?
protected ViewGroup.LayoutParams generateDefaultLayoutParams ()
返回一組寬度為WRAP_CONTENT,高度為WRAP_CONTENT,坐標(biāo)是(0,0)的布局參數(shù)
返回值
一組默認(rèn)的布局參數(shù)或null值
?
protected void onLayout (boolean changed, int l, int t, int r, int b)
在此視圖view給他的每一個(gè)子元素分配大小和位置時(shí)調(diào)用。 派生類(lèi)可以重寫(xiě)此方法并且重新安排他們子類(lèi)的布局。
參數(shù)
changed?? 這是當(dāng)前視圖view的一個(gè)新的大小或位置
l??????? 相對(duì)于父節(jié)點(diǎn)的左邊位置
t??????? 相對(duì)于父節(jié)點(diǎn)的頂點(diǎn)位置
r??????? 相對(duì)于父節(jié)點(diǎn)的右邊位置
b?????? 相對(duì)于父節(jié)點(diǎn)的底部位置
?
protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
測(cè)量視圖以確定其內(nèi)容寬度和高度。此方法被measure(int, int)調(diào)用。需要被子類(lèi)重寫(xiě)以提供對(duì)其內(nèi)容準(zhǔn)確高效的測(cè)量。
約定:當(dāng)重寫(xiě)此方法時(shí),你必須調(diào)用setMeasuredDimension(int, int)來(lái)保存當(dāng)前視圖view的寬度和高度。不成功調(diào)用此方法將會(huì)導(dǎo)致一個(gè)IllegalStateException異常,是由measure(int, int)拋出。所以調(diào)用父類(lèi)的onMeasure(int, int)方法是必須的。
父類(lèi)的實(shí)現(xiàn)是以背景大小為默認(rèn)大小,除非MeasureSpec(測(cè)量細(xì)則)允許更大的背景。子類(lèi)可以重寫(xiě)onMeasure(int,int)以對(duì)其內(nèi)容提供更佳的尺寸。
如果此方法被重寫(xiě),那么子類(lèi)的責(zé)任是確認(rèn)測(cè)量高度和測(cè)量寬度要大于視圖view的最小寬度和最小高度(getSuggestedMinimumHeight() and getSuggestedMinimumWidth()),使用這兩個(gè)方法可以取得最小寬度和最小高度。
參數(shù)
widthMeasureSpec????????? 強(qiáng)加于父節(jié)點(diǎn)的橫向空間要求。要求是使用View.MeasureSpec進(jìn)行編碼
heightMeasureSpec???????? 強(qiáng)加于父節(jié)點(diǎn)的縱向空間要求。要求是使用View.MeasureSpec進(jìn)行編碼。
?
補(bǔ)充
???????? 文件鏈接
?????????????????? Android的幾種布局方式
?????????????????? 第六講:用戶(hù)界面 View(二)
?????????????????? 如何動(dòng)態(tài)改變 AbsoluteLayout布局中其它布局的坐標(biāo)
???????? 示例代碼
<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>
?