电竞比分网-中国电竞赛事及体育赛事平台

分享

Android layout屬性詳細說明

 dmw_zgl 2014-11-20
Android layout 屬性詳細說明
文本總結了 Android4.2 layout 中用到的視圖屬性,包括 View 的屬性和 TextView 的屬性。這些 屬性適用于所有繼承于 View 或者 TextView 的控件,包括 Button、EditText、ListView、 ImageView 等等幾乎所有的 widget 控件。具體用到某個 widget 控件時,可以通過查看該 widget 的繼承關系,來判斷本文中的屬性是否適用于該控件。 例如,可以通過以下方法判斷 Button 是否能使用 View 或 TextView 的屬性。 打開 Android 官網(wǎng) Button 頁面,查看有關 Button 的繼承關系。如下(紅色字體): java.lang.Object ? android.view.View ? android.widget.TextView ? android.widget.Button 從上,我們可以看出 Button 繼承于 TextView,所以 TextView 的所有屬性 Button 都可以使用; 而 TextView 繼承于 View,所以 View 的所有屬性 Button 也可以使用。

View 屬性說明
下面對 View 的屬性進行詳細說明 android:alpha 關聯(lián)方法: setAlpha(float) 屬性說明: 視圖透明度,值在0-1之間。0為完全透明,1為完全不透明。 android:background 關聯(lián)方法: setBackgroundResource(int) 屬性說明: 視圖背景 android:clickable 關聯(lián)方法: setClickable(boolean) 屬性說明: 視圖是否可點擊 android:contentDescription 關聯(lián)方法: setContentDescription(CharSequence) 屬性說明: 設置 View 的備注說明,作為一種輔助功能提供,為一些沒有文字描述的 View 提供說明

android:drawingCacheQuality 關聯(lián)方法: setDrawingCacheQuality(int) 屬性說明: "設置繪圖時半透明質量。有可以取以下3個值 auto——默認,由框架決定 high——高質 量,使用較高的顏色深度,消耗更多的內存 low——低質量,使用較低的顏色深度,但是用更少的內 存" android:duplicateParentState 關聯(lián)方法: 屬性說明: 如果設置此屬性,將直接從父容器中獲取繪圖狀態(tài)(光標,按下等) android:fadeScrollbars 關聯(lián)方法: setScrollbarFadingEnabled(boolean) 屬性說明: 定義在 ScrollBar 沒有使用時,是否褪色。 android:fadingEdgeLength 關聯(lián)方法: getVerticalFadingEdgeLength() 屬性說明: 設置邊框漸變的長度。 android:filterTouchesWhenObscured 關聯(lián)方法: setFilterTouchesWhenObscured(boolean) 屬性說明: view 所在窗口被其它可見窗口遮住時,是否過濾觸摸事件。 android:fitsSystemWindows 關聯(lián)方法: setFitsSystemWindows(boolean) 屬性說明: 設置布局調整時是否考慮系統(tǒng)窗口(如狀態(tài)欄) android:focusable 關聯(lián)方法: setFocusable(boolean) 屬性說明: 設置是否獲得焦點。若有 requestFocus()被調用時,后者優(yōu)先處理。注意在表單中想設 置某一個如 EditText 獲取焦點,光設置這個是不行的,需要將這個 EditText 前面的 focusable 都設 置為 false 才行。在 Touch 模式下獲取焦點需要設置 focusableInTouchMode 為 true。 android:focusableInTouchMode 關聯(lián)方法: setFocusableInTouchMode(boolean) 屬性說明: 設置在 Touch 模式下 View 是否能取得焦點。 android:hapticFeedbackEnabled 關聯(lián)方法: setHapticFeedbackEnabled(boolean) 屬性說明: 是否啟用觸摸反饋,啟用后就是在點擊等操作時會有震動等反饋效果 android:id 關聯(lián)方法: setId(int) 屬性說明: 給當前 View 設置一個在當前 layout.xml 中的唯一編號,可以通過調用 View.findViewById() 或 Activity.findViewById()根據(jù)這個編號查找到對應的 View。不同的 layout.xml 之間定義相同的 id 不會沖突。 android:importantForAccessibility 關聯(lián)方法: setImportantForAccessibility(int) 屬性說明: 設置可達性的重要性

android:isScrollContainer 關聯(lián)方法: setScrollContainer(boolean) 屬性說明: 設置當前 View 為滾動容器。這里沒有測試出效果來,ListView/ GridView/ ScrollView 根本就不用設置這個屬性,而 EdidText 設置 android:scrollbars 也能出滾動條 android:keepScreenOn 關聯(lián)方法: setKeepScreenOn(boolean) 屬性說明: 視圖在可見的情況下是否保持喚醒狀態(tài)。 android:layerType 關聯(lián)方法: setLayerType(int,Paint) 屬性說明: "設置指定層的類型,可以取以下3個值: none——不指定 software——軟件層。 hardware——硬件層。使用硬件加速。" android:layoutDirection 關聯(lián)方法: setLayoutDirection(int) 屬性說明: 定義布局圖紙的方向 android:longClickable 關聯(lián)方法: setLongClickable(boolean) 屬性說明: 是否響應長點擊事件 android:minHeight 關聯(lián)方法: setMinimumHeight(int) 屬性說明: 設置視圖最小高度 android:minWidth 關聯(lián)方法: setMinimumWidth(int) 屬性說明: 設置視圖最小寬度 android:nextFocusDown 關聯(lián)方法: setNextFocusDownId(int) 屬性說明: 向下移動焦點時,下一個獲取焦點的 view 的 id android:nextFocusForward 關聯(lián)方法: setNextFocusForwardId(int) 屬性說明: 下一個獲取焦點的 view 的 id android:nextFocusLeft 關聯(lián)方法: setNextFocusLeftId(int) 屬性說明: 向左移動焦點時,下一個獲取焦點的 view 的 id android:nextFocusRight 關聯(lián)方法: setNextFocusRightId(int) 屬性說明: 向右移動焦點時,下一個獲取焦點的 view 的 id android:nextFocusUp 關聯(lián)方法: setNextFocusUpId(int) 屬性說明: 向上移動焦點時,下一個獲取焦點的 view 的 id

android:onClick 關聯(lián)方法: 屬性說明: 點擊時,要調用的方法的名稱。 android:padding 關聯(lián)方法: setPaddingRelative(int,int,int,int) 屬性說明: 設置上下左右的邊距 android:paddingBottom 關聯(lián)方法: setPaddingRelative(int,int,int,int) 屬性說明: 下邊距 android:paddingEnd 關聯(lián)方法: setPaddingRelative(int,int,int,int) 屬性說明: 與 android:paddingRight 相同 android:paddingLeft 關聯(lián)方法: setPadding(int,int,int,int) 屬性說明: 左邊距 android:paddingRight 關聯(lián)方法: setPadding(int,int,int,int) 屬性說明: 右邊距 android:paddingStart 關聯(lián)方法: setPaddingRelative(int,int,int,int) 屬性說明: android:paddingLeft 相同 android:paddingTop 關聯(lián)方法: setPaddingRelative(int,int,int,int) 屬性說明: 上邊距 android:requiresFadingEdge 關聯(lián)方法: setVerticalFadingEdgeEnabled(boolean) 屬性說明: 定義滾動時邊緣是否褪色 android:rotation 關聯(lián)方法: setRotation(float) 屬性說明: 旋轉度數(shù) android:rotationX 關聯(lián)方法: setRotationX(float) 屬性說明: 水平旋轉度數(shù) android:rotationY 關聯(lián)方法: setRotationY(float) 屬性說明: 豎直旋轉度數(shù) android:saveEnabled 關聯(lián)方法: setSaveEnabled(boolean)

屬性說明: 在配置改變等情況出現(xiàn)時是否保存 view 的狀態(tài)數(shù)據(jù)。如果你的 view 有 id,那默認系統(tǒng)就 會幫你保存。 android:scaleX 關聯(lián)方法: setScaleX(float) 屬性說明: 水平方向縮放比例 android:scaleY 關聯(lián)方法: setScaleY(float) 屬性說明: 豎直方向縮放比例 android:scrollX 關聯(lián)方法: 屬性說明: x 方向的滾動偏移。即在水平方向滾動了多少距離 android:scrollY 關聯(lián)方法: 屬性說明: y 方向的滾動偏移。即在豎直方向滾動了多少距離 android:scrollbarAlwaysDrawHorizontalTrack 關聯(lián)方法: 屬性說明: 是否總是繪制水平滾動條的滾動軌道 android:scrollbarAlwaysDrawVerticalTrack 關聯(lián)方法: 屬性說明: 是否總是繪制豎直滾動條的滾動軌道 android:scrollbarDefaultDelayBeforeFade 關聯(lián)方法: setScrollBarDefaultDelayBeforeFade(int) 屬性說明: 滾動條在 n 毫秒后開始淡出。 android:scrollbarFadeDuration 關聯(lián)方法: setScrollBarFadeDuration(int) 屬性說明: 滾動條用多長時間淡出完畢。 android:scrollbarSize 關聯(lián)方法: setScrollBarSize(int) 屬性說明: 設置滾動條的尺寸。垂直滾動條的寬度、水平滾動條的高度 android:scrollbarStyle 關聯(lián)方法: setScrollBarStyle(int) 屬性說明: "滾動條的風格。共4組值: insideOverlay——內貼圖 insideInset——內插圖 outsideOverlay——外貼圖 outsideInset——外插圖。 inside 就是滾動條在繪制在 padding 以 內;outside 就是不需要繪制在 padding 內(即 view 的邊界處);Overlay 是貼圖,就是直接覆蓋 在內容的上方,這樣內容可能會顯示到滾動條下方去;Inset 是插圖,就是會在對應 padding 上加上 滾動條的寬度,以不讓內容顯示到滾動條下面去。"

android:scrollbarThumbHorizontal 關聯(lián)方法: 屬性說明: 水平滾動塊的 drawable 對象 android:scrollbarThumbVertical 關聯(lián)方法: 屬性說明: 豎直滾動塊的 drawable 對象 android:scrollbarTrackHorizontal 關聯(lián)方法: 屬性說明: 水平滾動條滾動軌道的 drawable 對象 android:scrollbarTrackVertical 關聯(lián)方法: 屬性說明: 豎直滾動條滾動軌道的 drawable 對象 android:scrollbars 關聯(lián)方法: 屬性說明: "設置可顯示的滾動條。有3個取值: none——不顯示滾動條 horizontal——顯示水平滾動 條 vertical——顯示豎直滾動條" android:soundEffectsEnabled 關聯(lián)方法: setSoundEffectsEnabled(boolean) 屬性說明: 點擊或觸摸該 view 時,是否需要有聲音效果 android:tag 關聯(lián)方法: 屬性說明: string 標識。類似 id,id 是整數(shù)標識。 android:textAlignment 關聯(lián)方法: setTextAlignment(int) 屬性說明: 設置文本的顯示方式。 android:textDirection 關聯(lián)方法: setTextDirection(int) 屬性說明: 設置文本的顯示方向。 android:transformPivotX 關聯(lián)方法: setPivotX(float) 屬性說明: 水平方向偏轉量 android:transformPivotY 關聯(lián)方法: setPivotY(float) 屬性說明: 豎直方向偏轉量 android:translationX 關聯(lián)方法: setTranslationX(float) 屬性說明: 水平方向的移動距離

android:translationY 關聯(lián)方法: setTranslationY(float) 屬性說明: 豎直方向的移動距離 android:visibility 關聯(lián)方法: setVisibility(int) 屬性說明: "view 的可見性。有3個取值: gone——不可見,同時不占用 view 的空間; invisible— —不可見,但占用 view 的空間; visible——可見"

TextView 屬性說明
下面對 TextView 的屬性進行說明 android:autoLink 關聯(lián)方法: setAutoLinkMask(int) 屬性說明: 設置是否“當文本為 URL 鏈接/email/電話號碼/map 時,文本顯示為可點擊的鏈接”。 可選值(none/web/email/phone/map/all) android:autoText 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 如果設置,將自動執(zhí)行輸入值的拼寫糾正。此處無效果,在顯示輸入法并輸入的時候起作 用。 android:bufferType 關聯(lián)方法: setText(CharSequence,TextView.BufferType) 屬性說明: 指定 getText()方式取得的文本類別。選項 editable 類似于 StringBuilder 可追加字符, 也就是說 getText 后可調用 append 方法設置文本內容。 android:capitalize 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 設置自動大寫屬性。比如設置為2,自動大寫單詞首字符;設置為1,自動大寫每句話的首 字母等等。 android:cursorVisible 關聯(lián)方法: setCursorVisible(boolean) 屬性說明: 設定光標為顯示/隱藏,默認顯示。 android:digits 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 設置允許輸入哪些字符。如“1234567890.+-*/%? n()” android:drawableBottom 關聯(lián)方法: setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)

屬性說明: 在 text 的下方輸出一個 drawable。如果指定一個顏色的話會把 text 的背景設為該顏色, 并且同時和 background 使用時覆蓋后者。 android:drawableEnd 關聯(lián)方法: setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int) 屬性說明: 在文本結尾處顯示 drawable 對象。它的值可以是其它資源的引用,比如, "@[+][package:]type:name"或者"?[package:][type:]name";也可以是顏色值,如"#rgb", "#argb", "#rrggbb", or "#aarrggbb"。 android:drawableLeft 關聯(lián)方法: setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) 屬性說明: 在 text 的左邊輸出一個 drawable。 android:drawablePadding 關聯(lián)方法: setCompoundDrawablePadding(int) 屬性說明: 設置 text 與 drawable 的間隔,與 drawableLeft、drawableRight、drawableTop、 drawableBottom 一起使用,可設置為負數(shù),單獨使用沒有效果。 android:drawableRight 關聯(lián)方法: setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) 屬性說明: 在 text 的右邊輸出一個 drawable。 android:drawableStart 關聯(lián)方法: setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int) 屬性說明: 在文本開始處顯示 drawable 對象。它的值可以是其它資源的引用,比如, "@[+][package:]type:name"或者"?[package:][type:]name";也可以是顏色值,如"#rgb", "#argb", "#rrggbb", or "#aarrggbb"。 android:drawableTop 關聯(lián)方法: setCompoundDrawablesWithIntrinsicBounds(int,int,int,int) 屬性說明: 在 text 的正上方輸出一個 drawable。 android:editable 關聯(lián)方法: 屬性說明: 設置是否可編輯。這里無效果,在 EditView 中才有效果。 android:editorExtras 關聯(lián)方法: setInputExtras(int) 屬性說明: 設置文本的額外的輸入數(shù)據(jù)。在 EditView 中才有效果。 android:ellipsize 關聯(lián)方法: setEllipsize(TextUtils.TruncateAt) 屬性說明: 設置當文字過長時,該控件該如何顯示。有如下值設置:”start”—–省略號顯示在開 頭;”end”——省略號顯示在結尾;”middle”—-省略號顯示在中間;”marquee” ——以跑馬 燈的方式顯示(動畫橫向移動) android:ems 關聯(lián)方法: setEms(int) 屬性說明: 設置 TextView 的寬度為 N 個字符的寬度。

android:fontFamily 關聯(lián)方法: setTypeface(Typeface) 屬性說明: 文本的字形體系。 android:freezesText 關聯(lián)方法: setFreezesText(boolean) 屬性說明: 設置保存文本的內容以及光標的位置。 android:gravity 關聯(lián)方法: setGravity(int) 屬性說明: 設置文本位置,如設置成“center”,文本將居中顯示。 android:height 關聯(lián)方法: setHeight(int) 屬性說明: 設置文本區(qū)域的高度,支持度量單位:px(像素)/dp/sp/in/mm(毫米) android:hint 關聯(lián)方法: setHint(int) 屬性說明: Text 為空時顯示的文字提示信息,可通過 textColorHint 設置提示信息的顏色。 android:imeActionId 關聯(lián)方法: setImeActionLabel(CharSequence,int) 屬性說明: 設置 IME 動作 ID。 android:imeActionLabel 關聯(lián)方法: setImeActionLabel(CharSequence,int) 屬性說明: 設置 IME 動作標簽。在 EditView 再做說明。 android:imeOptions 關聯(lián)方法: setImeOptions(int) 屬性說明: 附加功能,設置右下角 IME 動作與編輯框相關的動作,如 actionDone 右下角將顯示一個 “完成”,而不設置默認是一個回車符號。 android:includeFontPadding 關聯(lián)方法: setIncludeFontPadding(boolean) 屬性說明: 設置文本是否包含頂部和底部額外空白,默認為 true。 android:inputMethod 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 為文本指定輸入法,需要完全限定名(完整的包名)。例如: com.google.android.inputmethod.pinyin,但是這里報錯找不到。 android:inputType 關聯(lián)方法: setRawInputType(int) 屬性說明: 設置文本的類型,用于幫助輸入法顯示合適的鍵盤類型。在 EditView 中再詳細說明,這 里無效果。

android:lineSpacingExtra 關聯(lián)方法: setLineSpacing(float,float) 屬性說明: 設置行間距。 android:lineSpacingMultiplier 關聯(lián)方法: setLineSpacing(float,float) 屬性說明: 設置行間距的倍數(shù)。如”1.2” android:lines 關聯(lián)方法: setLines(int) 屬性說明: 設置文本的行數(shù),設置兩行就顯示兩行,即使第二行沒有數(shù)據(jù)。 android:linksClickable 關聯(lián)方法: setLinksClickable(boolean) 屬性說明: 設置鏈接是否點擊連接,即使設置了 autoLink。 android:marqueeRepeatLimit 關聯(lián)方法: setMarqueeRepeatLimit(int) 屬性說明: 在 ellipsize 指定 marquee 的情況下,設置重復滾動的次數(shù),當設置為 marquee_forever 時表示無限次。 android:maxEms 關聯(lián)方法: setMaxEms(int) 屬性說明: 設置 TextView 的寬度為最長為 N 個字符的寬度。與 ems 同時使用時覆蓋 ems 選項。 android:maxHeight 關聯(lián)方法: setMaxHeight(int) 屬性說明: 設置文本區(qū)域的最大高度 android:maxLength 關聯(lián)方法: setFilters(InputFilter) 屬性說明: 限制顯示的文本長度,超出部分不顯示。 android:maxLines 關聯(lián)方法: setMaxLines(int) 屬性說明: 設置文本的最大顯示行數(shù),與 width 或者 layout_width 結合使用,超出部分自動換行, 超出行數(shù)將不顯示。 android:maxWidth 關聯(lián)方法: setMaxWidth(int) 屬性說明: 設置文本區(qū)域的最大寬度 android:minEms 關聯(lián)方法: setMinEms(int) 屬性說明: 設置 TextView 的寬度為最短為 N 個字符的寬度。與 ems 同時使用時覆蓋 ems 選項。 android:minHeight 關聯(lián)方法: setMinHeight(int) 屬性說明: 設置文本區(qū)域的最小高度

android:minLines 關聯(lián)方法: setMinLines(int) 屬性說明: 設置文本的最小行數(shù),與 lines 類似。 android:minWidth 關聯(lián)方法: setMinWidth(int) 屬性說明: 設置文本區(qū)域的最小寬度 android:numeric 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 如果被設置,該 TextView 有一個數(shù)字輸入法。此處無用,設置后唯一效果是 TextView 有點擊效果,此屬性在 EdtiView 將詳細說明。 android:password 關聯(lián)方法: setTransformationMethod(TransformationMethod) 屬性說明: 以小點”.”顯示文本 android:phoneNumber 關聯(lián)方法: setKeyListener(KeyListener) 屬性說明: 設置為電話號碼的輸入方式。 android:privateImeOptions 關聯(lián)方法: setPrivateImeOptions(String) 屬性說明: 設置輸入法選項,在 EditText 中才有作用。 android:scrollHorizontally 關聯(lián)方法: setHorizontallyScrolling(boolean) 屬性說明: 設置文本超出 TextView 的寬度的情況下,是否出現(xiàn)橫拉條。 android:selectAllOnFocus 關聯(lián)方法: setSelectAllOnFocus(boolean) 屬性說明: 如果文本是可選擇的,讓他獲取焦點而不是將光標移動為文本的開始位置或者末尾位置。 TextView 中設置后無效果。 android:shadowColor 關聯(lián)方法: setShadowLayer(float,float,float,int) 屬性說明: 指定文本陰影的顏色,需要與 shadowRadius 一起使用。 android:shadowDx 關聯(lián)方法: setShadowLayer(float,float,float,int) 屬性說明: 設置陰影橫向坐標開始位置。 android:shadowDy 關聯(lián)方法: setShadowLayer(float,float,float,int) 屬性說明: 設置陰影縱向坐標開始位置。 android:shadowRadius 關聯(lián)方法: setShadowLayer(float,float,float,int) 屬性說明: 設置陰影的半徑。設置為0.1就變成字體的顏色了,一般設置為3.0的效果比較好。

android:singleLine 關聯(lián)方法: setTransformationMethod(TransformationMethod) 屬性說明: 設置單行顯示。如果和 layout_width 一起使用,當文本不能全部顯示時,后面用“?” 來表示。如 android:text="test_ singleLine " android:singleLine="true" android:layout_width="20dp"將只顯示“t?”。如果不設置 singleLine 或者設置為 false,文本 將自動換行 android:text 關聯(lián)方法: setText(CharSequence,TextView.BufferType) 屬性說明: 設置顯示文本. android:textAllCaps 關聯(lián)方法: setAllCaps(boolean) 屬性說明: 設置文本全為大寫。值為"true"或"false"。 android:textAppearance 關聯(lián)方法: 屬性說明: 設置文字外觀。如“?android:attr/textAppearanceLargeInverse android:textColor 關聯(lián)方法: setTextColor(int) 屬性說明: 設置文本顏色 android:textColorHighlight 關聯(lián)方法: setHighlightColor(int) 屬性說明: 被選中文字的底色,默認為藍色 android:textColorHint 關聯(lián)方法: setHintTextColor(int) 屬性說明: 設置提示信息文字的顏色,默認為灰色。與 hint 一起使用。 android:textColorLink 關聯(lián)方法: setLinkTextColor(int) 屬性說明: 文字鏈接的顏色. android:textIsSelectable 關聯(lián)方法: isTextSelectable() 屬性說明: 設置非編輯文本可否被選擇。值為"true"或"false"。 android:textScaleX 關聯(lián)方法: setTextScaleX(float) 屬性說明: 設置文字之間間隔,默認為1.0f。 android:textSize 關聯(lián)方法: setTextSize(int,float) 屬性說明: 設置文字大小,推薦度量單位”sp”,如”15sp” android:textStyle 關聯(lián)方法: setTypeface(Typeface)

屬性說明: 設置字形[bold(粗體) 0, italic(斜體) 1, bolditalic(又粗又斜) 2] 可以設置一個或多個, 用“|”隔開 android:typeface 關聯(lián)方法: setTypeface(Typeface) 屬性說明: 設置文本字體,必須是以下常量值之一:normal 0, sans 1, serif 2, monospace(等寬 字體) 3] android:width 關聯(lián)方法: setWidth(int) 屬性說明: 設置文本區(qū)域的寬度,支持度量單位:px(像素)/dp/sp/in/mm(毫米)。

參考文檔
1, (View)Android 官方文檔 —— View 2, (TextView)Android 官方文檔 —— TextView 3, (View)Android2.2 API 中文文檔系列(5) —— View 4, (View)view 使用 5, (View)android ListView 幾個比較特別的屬性 6, (View)第三講 Layout 文件屬性講解 7, (TextView)Android2.2 API 中文文檔系列(1) —— TextView

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多