android學習之路(一)

學到知識就記錄在這裏!


1.android studio中 project相當於Eclipse裏Workspace,studio中的module相當於eclipse中的project;

2.http://androidxref.com     android系統源碼網站

3.www.androiddevtools.cn    android鏡像網站

4.在Editor標籤中選擇 General (一般 )在選擇Code completion 選項,在Code sensitive completion中選擇None,即代碼提示不區分大小寫

5.Android build tools是android sdk的Build 工具 建議保持更新。對應着gradle中module下的build.gradle中的buildtoolsVersion屬性:


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"


6.ducumentation for android sdk : sdk api的文檔資源;sources for android sdk :Android的源代碼壓縮包;

7.android device Monitor(監測儀);

8.這裏說了一點如果用戶設置了requestWindowFeature(window.featyre_NO_TITLE)來設置全票顯示,視圖樹中的佈局就只有Content了,解釋了爲什麼requestWindowFeature這個方法一定要在setContentView之前設置才能生效的原因;當程序在oncreate中調用setContentView後,activityManagerService會 回調onresume方法,此時系統才把整個Decorview添加到phone window中,完成繪製;

9.View的測量:MeasureSpec類:通過他測量view,一個32位的INT值,高2位是測量模式,低30位爲測量大小;

模式分以下3中:

1)EXACTLY精準值模式 100dp math_parent

2)AT_MOST最大值模式 wrap_content

3)UNSPECIFIED自定義VIEW使用


如果想要自定義的VIEW支持wrap_content屬性,就得重寫onMeasure P36;

10. 自定義VIEW:

自定義了一個Textview 初始化畫筆顏色時使用了:

paint1.setColor(getResources().getColor(android.R.color.holo_blue_light));
getResources();方法:是獲取項目中的資源文件可以用來獲取你說的string,xml還可以獲取圖片,音樂,視頻等資源文件。

11.一個最簡單的自定義組件,class代碼如下:

public class mTextView extends TextView{

    Paint paint1;
    Paint paint2;
    public mTextView(Context context,AttributeSet attributeSet){
        super(context,attributeSet);
        paint1=new Paint();
        paint1.setColor(getResources().getColor(android.R.color.holo_blue_light));
        paint1.setStyle(Paint.Style.FILL);
        paint2=new Paint();
        paint2.setColor(Color.YELLOW);
        paint2.setStyle(Paint.Style.FILL);

    }

    public mTextView(Context context) {
        super(context);
        paint1=new Paint();
        paint1.setColor(getResources().getColor(android.R.color.holo_blue_light));
        paint1.setStyle(Paint.Style.FILL);
        paint2=new Paint();
        paint2.setColor(Color.YELLOW);
        paint2.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.drawRect(0,0,getMeasuredWidth(),getMeasuredHeight(),paint1);
        canvas.drawRect(10,10,getMeasuredWidth()-10,getMeasuredHeight()-10,paint2);
        canvas.save();
        canvas.translate(10,0);

        //在回調父類方法前,實現自己的邏輯,對textView來說是繪製文本前
        super.onDraw(canvas);
        //在回調父類方法前,實現自己的邏輯,對textView來說是繪製文本後
        canvas.restore();
    }
}
注意一定要實現2個構造函數:
mTextView(Context context,AttributeSet attributeSet)
mTextView(Context context) {

否則程序不能正確運行 會出現錯誤


12.遇到一些問題 關於application類,於是去學習了一下:

在android源碼中對他的描述是;

        * Base class for those who need to maintain global application state. You can
        * provide your own implementation by specifying its name in your
        * AndroidManifest.xml's <application> tag, which will cause that class
        * to be instantiated for you when the process for your application/package is
        * created.

   SDK中的描述:Application類是爲了那些需要保存全局變量設計的基本類,你可以在AndroidManifest.xml的<application>標籤中進行自己的實現,這樣的結果是:當你的       application或者包被建立的時候將引起那個類被建立。

理解:就是說application是用來保存全局變量的,並且是在package創建的時候就跟着存在了。所以當我們需要創建全局變量的時候,不需 要再像j2se那樣需要創建public權限的static變量,而直接在application中去實現。只需要調用Context的getApplicationContext或者Activity的getApplication方法來獲得一個application對象,再做出相應 的處理。


13.view是組件是所有UI控件、容器控件的基類

14.activity包涵了一個setTheme(int resid)方法來設置窗口風格,如不顯示actionbar 或者以對話框形式顯示窗口。

15.activity service broadcastReceiver三種組件之間的通信都以intent 作爲載體。

16簽名的主要作用:告訴外界這個應用程序由我開發,有祕鑰,一般情況下一個人使用同一祕鑰 發佈自己產品 可直接替換以前的版本。

17view類:

View類的XML屬性、相關方法及說明

XML屬性

相關方法

說明

android:alpha

setAlpha(float)

設置該組件的透明度

android:background

setBackgroundResource(int)

設置該組件的背景顏色

android:clickable

setClickable(boolean)

設置該組件是否可以激發單擊事件

android:contentDescription

setContentDescription(CharSequence)

設置該組件的主要描述信息

android:drawingCacheQuality

setDrawingCacheQuality(iint)

設置該組件所使用的繪製緩存的質量

android:fadeScrollbars

setScrollbarFadingEnabled(boolean)

當不使用該組件的滾動條時,是否淡出顯示滾動條

android:fadingEdge

setVerticalFadingEdgeEnabled(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:minHeight

setMinimumHeight(int)

設置該組件的最小高度

android:minWidth

setMinimumWidtht(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:paddingLeft

setPadding(int,int,int,int)

在組件的左邊設置填充區域

android:paddingTop

setPadding(int,int,int,int)

在組件的上邊設置填充區域

android:paddingRight

setPadding(int,int,int,int)

在組件的右邊設置填充區域

android:paddingBottom

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:scrollbarAlwaysDrawHorizontalTrack

 

設置該組件是否總是顯示水平滾動條的軌跡

android:scrollbarAlwaysDrawVerticalTrack

 

設置該組件是否總是顯示垂直滾動條的軌跡

android:scrollbarDefaultDelayBeforeFade

setScrollbarDefaultDelayBeforeFade(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:不顯示滾動條

horizont:顯示水平滾動條

vertical:顯示垂直滾動條

android:soundEffectsEnabled

setSoundEffectsEnabled(boolean)

設置該組件被單擊時是否使用音效

android:tag

 

爲該組件設置一個字符串類型的tag值。接下來可通過View的getTag()獲取該字符串,或通過findViewWithTag()查找該組件

android:transformPivotX

setPivotX(float)

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

android:transformPivotY

setPivotY(float)

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

android:translationX

setTranslationX(float)

設置該組件在X方向上位移

android:translationY

setTranslationY(float)

設置該組件在Y方向上位移

android:

setVisibility(int)

設置該組件是否可見

 







































發佈了23 篇原創文章 · 獲贊 2 · 訪問量 5640
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章