Android有感(7):View類

來源:互聯網
上載者:User

標籤:

Android推薦使用XML檔案設計使用者介面,但實際上所有組件都提供了兩種使用方法:

1. 在XML布局檔案中設定XML屬

2. 在Java程式碼中調用方法


Android提供的官方文檔是必須學會使用的,可以去官網,推薦一個網站,裡面的文檔有一點(但不多)翻譯

http://www.android-doc.com/reference/packages.html


View類是所有UI組件的基類,其使用方法對所有的組件都是適用的:

XML屬性

相關方法

說明

android:accessibilityLiveRegion

setAccessibilityLiveRegion(int)

輔助性服務是否應自動通知更改視圖的內容描述或文本,或者子view的文字描述或常值內容;(none——不通知、polite——通知、assertive——打斷語音,並通知)

android:alpha

 setAlpha(float)

設定該組件的透明度(0-1)

android:background

 setBackgtoundResource(int)

設定該組件的背景顏色

android:clickable

 setClickable(boolean)

設定該組件是否可以激發點擊事件

android:contentDescription

setContentDescription(CharSequence)

設定組件的內容描述資訊

android:drawingCacheQuality

setDrawingCacheQuality(int)

設定組件所使用的繪製緩衝的品質

android:elevation

setElevation(float)

設定組件浮起來的高度(5.0)

android:fadingEdge

 setVerticalFadingEnabled(boolean)

設定滾動該組件時組件邊界是否使用淡出效果

android:fadingEdgeLength

 getVerticalFadingEdgeLength

設定淡出邊界長度

android:focusable

 setFocusable(boolean)

設定該組件是否可以得到焦點

android:focusableInTouchMode

 setFocusableInTouchMode(boolean)

設定該組件在觸摸模式下是否可以得到焦點

android:id

 setId(int)

設定該組件的唯一標示,java代碼中可通過findViewById來擷取它

android:isScrollContainer

setScrollContainer(boolean)

設定該組件是否作為可滾動容器使用

android:keepScreenOn

 setKeepScreenOn(boolean)

設定該組件是否會強制手機螢幕一直開啟

android:longClickable

setLongClickable(boolean)

設定該組件是否可以響應長單擊事件

android:layout_gravity

 

設定該組件在其容器中的對齊

android:layout_height

 setLayoutParams(ViewGroup.layoutParams params)

設定該組件在其父類容器中的布局高度

android:layout_width

 setLayoutParams(ViewGroup.LayoutParams params)

設定該組件在其父容器中的布局寬度

android:layout_margin

 

設定該組件在其父類容易中的布局時的頁面邊界

android:minHeight

 setMinimumHeight(int)

設定該組件的最小高度

android:minWidth

 setMinimumWidth(int)

設定該組件的最小寬度

android:nextFocusDown

 setNextFocusDownId(int)

設定焦點在該組件上,且單擊向下鍵時獲得焦點的組件ID

android:nextFocusLeft

 setNextFocusLeftId(int)

設定焦點在該組件上,且單擊向左鍵時獲得焦點的組件ID

android:nextFocusRight

 setNextFocusRightId(int)

設定焦點在該組件上,且單擊左鍵時獲得焦點的組件ID

android:nextFocusUp

 setNextFocusUpId(int)

設定焦點在該組件上,且單擊向上鍵獲得焦點的組件ID

android:onClick

 

為該組件的單擊事件綁定監聽器

android:padding

 setPadding(int,int,int,int)

在組件四邊設定填充地區

android:panddingBottom

 setPadding(int,int,int,int)

在組件的下面設定填充地區

android:paddingLeft

 setPadding(int,int,int,int)

在組件的左邊設定填充地區

android:paddingRight

 setPadding(int,int,int,int)

在組件的郵編設定填充地區

android:paddingTop

 setPadding(int,int,int,int)

在組件的上面設定填充地區

android:rotation

setRotation(float)

設定組件旋轉的角度

android:rotationX

setRotationX(float)

設定組件繞X軸旋轉的角度

android:rotationY

setRotationY(float)

設定組件繞Y軸旋轉的角度

android:saveEnabled

 setSaveEnabled(boolean)

如果設定為false,那當該組件被凍結師不會儲存它的狀態

android:scaleX

setScaleX(float)

設定該組件在水平方向的縮放比

android:scaleY

setScaleY(float)

設定該組件在豎直方向的縮放比

android:scrollX

 

該組件初始化後的水平滾動位移

android:scrollY

 

該組件初始化後的垂直滾動位移

android:scrollbarAlwaysDrawHoruzonTrack

 

設定該組件是否總是顯示水平捲軸的軌道

android:scrollbarAlwayDrawVerticalTrack

 

設定該組件是否在總是顯示垂直捲軸的軌道

android:scrollbarDefauitDelayBeforeFade

setScrollbarDefauitDelayBeforeFade(int)

設定捲軸在淡出隱藏隱藏前延遲多少秒

android:scrollbarFadeDuration

setScrollbarFadeDuration(int) 

設定捲軸淡出隱藏過程需要多少秒

android:scrollbarSize

setScrollbarSize(int)

設定垂直捲軸的寬度和水平捲軸的高度

android:scrollbarStyle

setScrollbarStyle(int) 

設定捲軸的風格和位置:insideOverlay/

insideInset/outsideOverlay/outsideInset

android:scrollbarThumbHorizontal

 

設定該組件水平捲軸的滑塊對應的Drawable對象

android:scrollbarThumbVertical 

 

設定該組件垂直捲軸的滑塊對應的Drawable對象

android:scrollbarTrackHorizontal

 

設定該組件水平捲軸的軌道對應的Drawable對象

android:scrollbarTrackVertical

 

設定該組件垂直捲軸的軌道對應的Drawable對象

android:scrollbars

 

設定顯示的捲軸種類none/horizontal/vertical

android:soundEffectsEnabled

 setSoundEffectsEnabled(boolean)

設定該組件被點擊時是否使用音效

android:tag

 

為該組件設定一個字串類型的tag值,可通過View的getTag()擷取該字串,可通過findViewWithTag()尋找該組件

android:textAlignment

setTextAlignment(int)

設定文本的顯示對齊

android:textDirection

setTextDirection(int)

設定文本的顯示方向

android:transformPivotX

setPivotX(float)

設定該組件旋轉時旋轉中心的X座標

android:transformPivotY

setPivotY(float)

設定該組件旋轉時旋轉中心的Y座標

android:translationX

setTranslationX(float)

設定該組件在X方向上的位移

android:translationY

setTranslationY(float)

設定該組件在Y方向上的位移

android:translationZ

setTranslationZ(float)

設定該組件在Z方向上的位移(5.0)

android:visibility

 setVisbility(int)

設定該組件是否可見

 

 

Android有感(7):View類

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.