Android Layout佈局及屬性



第一類:屬性值 true或者 false

 android:layout_centerHrizontal 水平居中
 android:layout_centerVertical 垂直居中
 android:layout_centerInparent 相對於父元素完全居中
 android:layout_alignParentBottom 貼緊父元素的下邊緣
 android:layout_alignParentLeft 貼緊父元素的左邊緣
 android:layout_alignParentRight 貼緊父元素的右邊緣
 android:layout_alignParentTop 貼緊父元素的上邊緣
 android:layout_alignWithParentIfMissing 如果對應的兄弟元素找不到的話就以父元素做參照物


 android:layout_alignParentStart緊貼父元素結束位置開始

 android:layout_alignParentEnd緊貼父元素結束位置結束

 android:animateLayoutChanges佈局改變時是否有動畫效果

 android:clipChildren定義子佈局是否一定要在限定的區域內

 android:clipToPadding定義佈局間是否有間距

 android:animationCache定義子佈局也有動畫效果

 android:alwaysDrawnWithCache定義子佈局是否應用繪圖的高速緩存

 android:addStatesFromChildren定義佈局是否應用子佈局的背景

 android:splitMotionEvents定義佈局是否傳遞touch事件到子佈局

 android:focusableInTouchMode定義是否可以通過touch獲取到焦點

 android:isScrollContainer定義佈局是否作爲一個滾動容器 可以調整整個窗體

 android:fadeScrollbars滾動條自動隱藏

 android:fitsSystemWindows設置佈局調整時是否考慮系統窗口(如狀態欄)

 android:visibility定義佈局是否可見

 android:requiresFadingEdge定義滾動時邊緣是否褪色

 android:clickable定義是否可點擊

 android:longClickable定義是否可長點擊

 android:saveEnabled設置是否在窗口凍結時(如旋轉屏幕)保存View的數據

 android:filterTouchesWhenObscured所在窗口被其它可見窗口遮住時,是否過濾觸摸事件

 android:keepScreenOn設置屏幕常亮

 android:duplicateParentState是否從父容器中獲取繪圖狀態(光標,按下等)

 android:soundEffectsEnabled點擊或觸摸是否有聲音效果

 android:hapticFeedbackEnabled設置觸感反饋


第二類:屬性值必須爲id的引用名“@id/id-name

 android:layout_alignBaseline 本元素的文本與父元素文本對齊

 android:layout_below 在某元素的下方
 android:layout_above 在某元素的的上方
 android:layout_toLeftOf 在某元素的左邊
 android:layout_toRightOf 在某元素的右邊

 android:layout_toStartOf本元素從某個元素開始

 android:layout_toEndOf本元素在某個元素結束

 android:layout_alignTop 本元素的上邊緣和某元素的的上邊緣對齊
 android:layout_alignLeft 本元素的左邊緣和某元素的的左邊緣對齊
 android:layout_alignBottom 本元素的下邊緣和某元素的的下邊緣對齊
 android:layout_alignRight 本元素的右邊緣和某元素的的右邊緣對齊


 android:layout_alignStart本元素與開始的父元素對齊

 android:layout_alignEnd本元素與結束的父元素對齊

 android:ignoreGravity 指定元素不受重力的影響

 android:layoutAnimation定義佈局顯示時候的動畫

 android:id 爲佈局添加ID方便查找

 android:tag爲佈局添加tag方便查找與類似

 android:scrollbarThumbHorizontal設置水平滾動條的drawable。

 android:scrollbarThumbVertical設置垂直滾動條的drawable

 android:scrollbarTrackHorizontal設置水平滾動條背景(軌跡)的色drawable

 android:scrollbarTrackVertical設置垂直滾動條背景(軌跡)的色drawable

 android:scrollbarAlwaysDrawHorizontalTrack 設置水平滾動條是否含有軌道

 android:scrollbarAlwaysDrawVerticalTrack 設置垂直滾動條是否含有軌道

 android:nextFocusLeft 設置左邊指定視圖獲得下一個焦點

 android:nextFocusRight設置右邊指定視圖獲得下一個焦點

 android:nextFocusUp設置上邊指定視圖獲得下一個焦點

 android:nextFocusDown設置下邊指定視圖獲得下一個焦點

 android:nextFocusForward設置指定視圖獲得下一個焦點

 android:contentDescription 說明

 android:OnClick 點擊時從上下文中調用指定的方法


第三類:屬性值爲具體的像素值,如30dip,40px,50dp

 android:layout_width定義本元素的寬度

 android:layout_height定義本元素的高度

 android:layout_margin 本元素離上下左右間的距離

 android:layout_marginBottom 離某元素底邊緣的距離
 android:layout_marginLeft 離某元素左邊緣的距離
 android:layout_marginRight 離某元素右邊緣的距離
 android:layout_marginTop 離某元素上邊緣的距離

 android:layout_marginStart本元素裏開始的位置的距離

 android:layout_marginEnd本元素裏結束位置的距離

 android:scrollX水平初始滾動偏移

 android:scrollY垂直初始滾動偏移

 android:background本元素的背景

 android:padding指定佈局與子佈局的間距

 android:paddingLeft指定佈局左邊與子佈局的間距

 android:paddingTop指定佈局上邊與子佈局的間距

 android:paddingRight指定佈局右邊與子佈局的間距

 android:paddingBottom指定佈局下邊與子佈局的間距

 android:paddingStart指定佈局左邊與子佈局的間距與android:paddingLeft相同

 android:paddingEnd指定佈局右邊與子佈局的間距與android:paddingRight相同

 android:fadingEdgeLength 設置邊框漸變的長度

 android:minHeight最小高度

 android:minWidth最小寬度

 android:translationX 水平方向的移動距離

 android:translationY垂直方向的移動距離

 android:transformPivotX相對於一點的水平方向偏轉量

 android:transformPivotY相對於一點的垂直方向偏轉量


第四類:屬性值問Android內置值的

 android:gravity控件佈局方式

 android:layout_gravity佈局方式

 android:persistentDrawingCachehua定義繪圖的高速緩存的持久性  

 android:descendantFocusability控制子佈局焦點獲取方式 常用於listView的item中包含多個控件 點擊無效

 android:scrollbars設置滾動條的狀態

 android:scrollbarStyle設置滾動條的樣式

 android:fitsSystemWindows設置佈局調整時是否考慮系統窗口(如狀態欄)

 android:scrollbarFadeDuration設置滾動條淡入淡出時間

 android:scrollbarDefaultDelayBeforeFade設置滾動條N毫秒後開始淡化,以毫秒爲單位。

 android:scrollbarSize設置滾動調大小

 android:fadingEdge 設置拉滾動條時 ,邊框漸變的放向

 android:drawingCacheQuality設置繪圖時半透明質量

 android:OverScrollMode滑動到邊界時樣式

 android:alpha設置透明度

 android:rotation旋轉度數

 android:rotationX水平旋轉度數

 android:rotationY垂直旋轉度數

 android:scaleX設置X軸縮放

 android:scaleY設置Y軸縮放

 android:verticalScrollbarPosition攝者垂直滾動條的位置

 android:layerType設定支持

 android:layoutDirection定義佈局圖紙的方向

 android:textDirection定義文字方向

 android:textAlignment文字對齊方式

 android:importantForAccessibility設置可達性的重要行

 android:labelFor添加標籤



Android RelativeLayout屬性



// 相對於給定ID控件
android:layout_above 將該控件的底部置於給定ID的控件之上;
android:layout_below 將該控件的底部置於給定ID的控件之下;
android:layout_toLeftOf 將該控件的右邊緣與給定ID的控件左邊緣對齊;
android:layout_toRightOf 將該控件的左邊緣與給定ID的控件右邊緣對齊;

android:layout_alignBaseline 將該控件的baseline與給定ID的baseline對齊;
android:layout_alignTop 將該控件的頂部邊緣與給定ID的頂部邊緣對齊;
android:layout_alignBottom 將該控件的底部邊緣與給定ID的底部邊緣對齊;
android:layout_alignLeft 將該控件的左邊緣與給定ID的左邊緣對齊;
android:layout_alignRight 將該控件的右邊緣與給定ID的右邊緣對齊;
// 相對於父組件
android:layout_alignParentTop 如果爲true,將該控件的頂部與其父控件的頂部對齊;
android:layout_alignParentBottom 如果爲true,將該控件的底部與其父控件的底部對齊;
android:layout_alignParentLeft 如果爲true,將該控件的左部與其父控件的左部對齊;
android:layout_alignParentRight 如果爲true,將該控件的右部與其父控件的右部對齊;
// 居中
android:layout_centerHorizontal 如果爲true,將該控件的置於水平居中;
android:layout_centerVertical 如果爲true,將該控件的置於垂直居中;
android:layout_centerInParent 如果爲true,將該控件的置於父控件的中央;
// 指定移動像素
android:layout_marginTop 上偏移的值;
android:layout_marginBottom 下偏移的值;
android:layout_marginLeft   左偏移的值;
android:layout_marginRight   右偏移的值;

example:
android:layout_below = "@id/***"
android:layout_alignBaseline = "@id/***"
android:layout_alignParentTop = true
android:layout_marginLeft = “10px”

[java] view plaincopy
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">
 <TextView
 android:id="@+id/label"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="Type here:"/>
 <EditText
 android:id="@+id/entry"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:background="@android:drawable/editbox_background"
 android:layout_below="@id/label"/>
 <Button
 android:id="@+id/ok"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@id/entry"
 android:layout_alignParentRight="true"
 android:layout_marginLeft="10dip"
 android:text="OK" />
 <Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_toLeftOf="@id/ok"
 android:layout_alignTop="@id/ok"
 android:text="Cancel" />
</RelativeLayout>

這是很常見的佈局內容,講解如下:
android:layout_below="@id/label"/>
將當前控件放置於id爲label 的控件下方。
android:layout_alignParentRight="true"
使當前控件的右端和父控件的右端對齊。這裏屬性值只能爲true或false,默認false。
android:layout_marginLeft="10dip"
使當前控件左邊空出相應的空間。
android:layout_toLeftOf="@id/ok"
使當前控件置於id爲ok的控件的左邊。
android:layout_alignTop="@id/ok"
使當前控件與id控件的上端對齊。

至此,我們已經發現,其屬性之繁多。下面簡單歸納一下:
第一類:屬性值爲true或false
*android:layout_centerHrizontal
*android:layout_centerVertical
*android:layout_centerInparent
*android:layout_alignParentBottom
*android:layout_alignParentLeft
*android:layout_alignParentRight
*android:layout_alignParentTop
*android:layout_alignWithParentIfMissing
第二類:屬性值必須爲id的引用名“@id/id-name
*android:layout_below
*android:layout_above
*android:layout_toLeftOf
*android:layout_toRightOf
*android:layout_alignTop
第三類:屬性值爲具體的像素值,如30dip,40px
*android:layout_marginBottom
*android:layout_marginLeft
*android:layout_marginRight
*android:layout_marginTop

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章