Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: 刘望舒

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Android进阶之光 — Reading Guide ## 【One-Line Pitch】 A practical, source-code-driven guide for Android developers who want to move beyond basic app building into advanced topics like Material Design, custom Views, and multithreading. Read this if you have 1–2 years of Android experience and want to understand *how* the framework works, not just *what* APIs to call. --- ## 【Book Arc】 - **Opening (~0%–10%)**: Android 5.0/6.0 new features — Material Design components, RecyclerView with waterfall layouts, CardView, and the new Notification styles (foldable, heads-up). This stage gets you productive with modern UI building blocks quickly. - **Early (~10%–23%)**: Runtime permissions (Android 6.0) and the Design Support Library deep-dive — Snackbar, TextInputLayout, FloatingActionButton, TabLayout, NavigationView, and CoordinatorLayout. The focus shifts from "what's new" to "how to build real screens with these tools." - **Early-to-Middle (~23%–39%)**: The View system core — View/ViewGroup hierarchy, coordinate systems, six ways to slide a View (layout(), offsetLeftAndRight(), LayoutParams, animation, scrollTo/scrollBy, Scroller), and a source-level walkthrough of the event dispatch mechanism (dispatchTouchEvent → onInterceptTouchEvent → onTouchEvent). - **Middle (~39%–48%)**: View's working pipeline — MeasureSpec, measure/layout/draw flows, and custom View development including custom attributes via TypedArray. This is the "roll up your sleeves" section where you build your own components. - **Late (~48%+)**: Multithreading begins — thread creation, interruption, and safe termination patterns. The book continues into concurrency topics that build on the UI foundation established earlier. --- ## 【Key Takeaways】 - **Material Design is the new baseline for Android UI** (Opening): RecyclerView with staggered grids gives you waterfall layouts in minutes, and CardView adds rounded corners and shadows with zero custom drawing. Use these instead of hand-rolling list UIs. - **Runtime permissions changed the developer contract** (Early): Android 6.0+ requires asking for permissions at runtime, not install time. Set `targetSdkVersion` below 23 to bypass this (legacy apps), or use annotation-based libraries like PermissionsDispatcher to avoid boilerplate — its `@RuntimePermissions`, `@NeedsPermission`, and `@OnPermissionDenied` annotations handle the flow for you. - **Design Support Library solves real UI problems** (Early): TextInputLayout gives you floating labels for login forms, TabLayout with `app:tabMode="scrollable"` fixes the "too many tabs squeezed together" problem, and CoordinatorLayout + AppBarLayout + CollapsingToolbarLayout creates the collapsing-header effect seen in modern apps like NetEase. - **View sliding has six distinct approaches, each with trade-offs** (Early): `layout()` and `offsetLeftAndRight()` are simple but manual; LayoutParams changes trigger re-layout; animations are smooth but don't change the actual position; `scrollTo/scrollBy` moves content within a View; Scroller adds fling-like physics with interpolators. - **Event dispatch is a three-method handoff chain** (Early): `dispatchTouchEvent` distributes, `onInterceptTouchEvent` intercepts (ViewGroup only), and `onTouchEvent` handles. The DOWN event initializes the touch target; understanding this chain is the key to fixing touch conflicts in custom containers. - **View measurement is driven by MeasureSpec** (Middle): The parent passes mode (EXACTLY, AT_MOST, UNSPECIFIED) and size to children. A custom ViewGroup must call `measureChildren()` and then set its own dimensions based on children's measured sizes — the sample code shows how to handle each MeasureSpec mode combination. - **Custom Views need custom attributes via TypedArray** (Middle): Define `declare-styleable` in XML, read values in the `AttributeSet` constructor with `obtainStyledAttributes()`, and always call `recycle()` to free resources. This is the standard pattern for making your View configurable from XML. - **Safe thread termination requires interruption, not force-stopping** (Late): Use `interrupt()` and handle `InterruptedException` properly — either re-throw it or restore the interrupt flag. Swallowing the exception silently breaks the cooperative cancellation contract. --- ## 【Reading Tips】 - **Skim the first 10%** if you already know Android 5.0 features — the Notification and App Links sections are mostly historical context. Focus instead on the RecyclerView waterfall pattern, which is still widely used. - **Deep-read the event dispatch section (~32%)** — it's the hardest part of the book but the most valuable. Trace the source code yourself alongside the text; the `mFirstTouchTarget` logic is subtle and worth understanding fully. - **The View workflow section (~39%) is reference material** — don't memorize the draw pipeline. Instead, bookmark the MeasureSpec handling patterns and the custom attribute recipe; you'll consult them when building custom Views. - **Code along with the Design Support Library chapter** — these are hands-on recipes (login screen, drawer menu, collapsing toolbar). Build each one in a scratch project to internalize the XML + Java pairing. - **If you're here for multithreading only**, jump to the Late section (~48%) — but note the excerpts only cover thread basics (creation, interruption, termination), not advanced concurrency utilities. --- ## 【Coverage Limits】 This guide covers the sampled excerpts (roughly the first half of the book): Android 5.0/6.0 features, Material Design components, View system internals, custom View development, and the start of multithreading. Later chapters on advanced concurrency, performance optimization, and architecture patterns are not covered by the available material. --- ##
Page 9
3.3.2 offsetLeftAndRight()与 offsetTopAndBottom() .................................................. 94 3.3.3 LayoutParams(改变布局参数) ..............................
View in text
Excerpt 2
setContentView(R.layout.activity_third_party); bt_call = (Button) this.findViewById(R.id.bt_call); bt_call.setOnClickListener(new View.OnClickListener() { @O...
View in text
Excerpt 3
w 再把事件处理工作交给 DecorView,之后再由 DecorView 将事件处理 工作交给根 ViewGroup。所以,我们从 ViewGroup 的 dispatchTouchEvent()方法开始分析,代码 如下所示: @Override public boolean dispatchTouchEven...
View in text
Excerpt 4
N_MOVE: int deltaX = x - lastInterceptX; int deltaY = y - lastInterceptY; if (Math.abs(deltaX) - Math.abs(deltaY) > 0) { //2 intercept = true; } break; case...
View in text
Excerpt 5
HTTP.UTF_8); //持续握手 HttpProtocolParams.setUseExpectContinue(mDefaultHttpParams, true); HttpClient mHttpClient = new DefaultHttpClient(mDefaultHttpParams); re...
View in text
Excerpt 6
onnection.allocations.add(new WeakReference<>(this)); } private void release(RealConnection connection) { for (int i = 0, size = connection.allocations.size(...
View in text
Excerpt 7
break; default: throw new IllegalStateException("Unknown thread mode: " + subscription. subscriberMethod.threadMode); } } 取出订阅方法的 threadMod(e 线程模式),之后根据 thre...
View in text
Excerpt 8
ble, 备用 Observable会忽略原有 Observable的 onError调用,不会将错误传递给观察者。作 为替代,它会发射备用 Observable的数据。 • onExceptionResumeNext:它和 onErrorResumeNext类似。不同的是,如果 onError收到 的 Thro...
View in text
Tags
AI categories
移动Programming LanguageBackend
ISBN: 7121315300
Publish Year: 2017
Language: Chinese
File Format: PDF
File Size: 12.9 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…