在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ Android/ 自定義View/ViewGroup以及高性能實現(xiàn)自定義UI
Launch mode 和 Intent flags專題
Canvas & Drawables
UTAustinX_UT.9.01x: Effective Thinking Through Mathematics
《JavaScript 語言精粹》
Memory leak專題
React基礎(chǔ)
《Test Driven Development: By Example》一書
Developer tools
安卓開發(fā)技能樹
<a rel="nofollow" href="https://mp.weixin.qq.com/s?__biz=MzA3NDM
Best Practices for Interaction and Engagement
各個安卓版本引入的主要新特性
Building Apps with Connectivity &amp; the Cloud
List.toArray()再強轉(zhuǎn)是一定會失敗的
深入Android frameworks
Google dev 100 days系列視頻
Building Apps with Contacts &amp; Sign-In
關(guān)系型數(shù)據(jù)庫設(shè)計范式
《App研發(fā)錄》一書
REST API設(shè)計
Google IO 2015摘要
自定義View/ViewGroup以及高性能實現(xiàn)自定義UI
安卓系統(tǒng)點擊事件處理
《50 Android Hacks》一書
Building Apps with Content Sharing
Flux基礎(chǔ)
<a rel="nofollow" href="http://developer.android.com/training/in
依賴注入(以Dagger 2為例)
Java同步機制
Java對象內(nèi)存的使用情況
JSR133(Java memory model)
Google官方Material Design手冊(<a rel="nofollow" href="http://develop
Futurice公司安卓團隊的建議
安卓性能優(yōu)化
  • 1.
Best Practices for Performance
<a rel="nofollow" href="http://www.vogella.com/tutorials/Android
<a rel="nofollow" href="http://blog.danlew.net/2014/11/19/styles
Handling Runtime Changes
<a rel="nofollow" href="http://www.vogella.com/tutorials/Android
Building Apps with Graphics &amp; Animation
<a rel="nofollow" href="http://tools.android.com/tech-docs/new-b
Android項目架構(gòu)
MVP(Model-View-Presenter)模式
<a rel="nofollow" href="http://www.infoq.com/cn/es6-in-depth/"">
《Android源碼設(shè)計模式解析與實戰(zhàn)》一書
Rx在Android中的最佳實踐
函數(shù)調(diào)用時,傳遞參數(shù)應(yīng)該是不可變的(Immutable)
ProGuard
面向?qū)ο罅笤瓌t(SOLID+)
深入理解Java虛擬機
深入Java深淺拷貝、immutable、unmodifiable
Best Practices for User Input
UI上的一些高效方式/最佳實踐
<a rel="nofollow" href="https://blog.stylingandroid.com/ripples-
Best Practices for User Interface
安卓測試驅(qū)動開發(fā)/安卓測試驗證
暗時間:學(xué)會正確思考
技術(shù)筆記
Aspect Oriented Programming(AOP)
Best Practices for Background Jobs
安卓系統(tǒng)動效專題
Feed系統(tǒng)的設(shè)計
Data binding(MVVM,Model-View-ViewModel)
Effective Java一書筆記
<a rel="nofollow" href="http://developer.android.com/training/in
Rx (Reactive eXtention)
MultiDex專題
一些很棒的點子
WebRTC

自定義View/ViewGroup以及高性能實現(xiàn)自定義UI

View繪制流程

當(dāng) Activity 接收到焦點的時候,它會被請求繪制布局,該請求由 Android framework 處理。繪制是從根節(jié)點開始,對布局樹進行 measure 和 draw。整個 View 樹的繪圖流程在ViewRoot.java類的performTraversals()函數(shù)展開,該函數(shù)所做的工作可簡單概況為是否需要重新計算視圖大小(measure)、是否需要重新安置視圖的位置(layout)、以及是否需要重繪(draw)。

  • measure

    • ViewGroup負責(zé)測量所有子View及自己,View負責(zé)測量自己;
    • View重寫onMeasure以實現(xiàn)自己的測量邏輯;
    • View在onMeasure中,根據(jù)傳入的widthMeasureSpec, heightMeasureSpec(父ViewGroup對自己的限制),以及自己的內(nèi)容顯示需要,計算出想要的寬高,通過setMeasuredDimension進行最終設(shè)置(該方法必須調(diào)用,否則拋異常),設(shè)置的寬高也是經(jīng)過位運算的值;
    • MeasureSpec值都是經(jīng)過位運算的,View類提供了一些方法從中讀取信息
    • 推薦按照以下方式實現(xiàn)

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
      
            // Try for a width based on our minimum
            int minw = getPaddingLeft() + getPaddingRight() + getSuggestedMinimumWidth();
            int w = resolveSizeAndState(minw, widthMeasureSpec, 1);
      
            // Whatever the width ends up being, ask for a height that would let the pie
            // get as big as it can
            int minh = getPaddingBottom() + getPaddingTop() + getSuggestedMinimumHeight();
            int h = resolveSizeAndState(minh, heightMeasureSpec, 0);
      
            setMeasuredDimension(w, h);
      
        }
    • 計算自己所需高度、寬度則通過重寫getSuggestedMinimumWidth,getSuggestedMinimumHeight來進行計算
    • 子View measure完之后,如果不符合父ViewGroup給出的約束(過大或過小),將觸發(fā)父ViewGroup對子View進行第二次measure,此時傳入的約束可能會發(fā)生變化,例如從限制最大值/最小值到給定具體值。

    • ViewGroup的measure過程包括:對于每個child,根據(jù)自己的measureSpec、child的LayoutParam、自己的padding,來計算child的measureSpec,然后傳給child,讓其自己進行上述的measure邏輯
  • layout

    • 首先要明確的是,子視圖的具體位置都是相對于父視圖而言的。View 的 onLayout 方法為空實現(xiàn),而 ViewGroup 的 onLayout 為 abstract 的,因此,如果自定義的 View 要繼承 ViewGroup 時,必須實現(xiàn) onLayout 函數(shù)。
    • measure完成后,就是根據(jù)每個子View確定顯示的大小,及其顯示規(guī)則,來排布每個子View了,這個排布就是設(shè)置子View的left, top, right, bottom了,注意子View的這些值都是相對于父ViewGroup的,而不是屏幕坐標(biāo)系的絕對位置。
  • draw

    • 應(yīng)該重寫的是onDraw方法,一定要重寫draw方法時一定要首先調(diào)用super.draw()
  • 一定要注意
    • 自定義View/ViewGroup一定要避免調(diào)用requestLayout,會導(dǎo)致整個view hierarchy的重繪,影響性能

自定義View實例

自定義ViewGroup實例

View的位置相關(guān)的幾個概念

  • X, Y, Z
    • View左上角在屏幕坐標(biāo)系上的坐標(biāo)
    • getX: mLeft + getTranslationX()
  • left, top, right, bottom
    • 相對于parent的位置(在parent中的位置),不建議代碼修改
  • translationX, translationY, translationZ
    • View相對于left, top, elevation的位置
    • 對X, Y, Z的設(shè)置,實際上是通過對這三個屬性設(shè)置實現(xiàn)的
    • 所以X, Y, Z可以由translationX, translationY, translationZ及l(fā)eft, top, elevation計算出來
  • height, measured height, width measured width
  • GlobalVisibleRect, LocalVisibleRect