Each View pushes dimension specifications down the tree • Determines the size requirement for a view • In order to parent to measure itself, needs to measure all children • Start from bottom Result: every View has stored its measurements.
top, int right, int bottom) • Called only on ViewGroups • ViewGroups let children know how they should be positioned calling “layout(left, top, right, bottom)”. • Lighter than onMeasure • Start from top Result: all child views are positioned using the sizes computed in the measure pass.
widthMeasureSpec, int heightMeasureSpec) Modes: • UNSPECIFIED: Used by a parent to determine the desired dimension of a child View. • EXACTLY: Child must use this size, and guarantee that all of its descendants will fit within this size. • AT MOST: Imposes a maximum size on the child. The child must guarantee that it and all of its descendants will fit within this size.
layout (width, height etc.) Values: • an exact number • MATCH_PARENT, View wants to be as big as its parent (minus padding) • WRAP_CONTENT, View wants to be just big enough to enclose its content (plus padding). Different subclasses of ViewGroup.LayoutParams for different subclasses of ViewGroup.
oldh) • Called when the size of this view has changed. • If need more control: override onMeasure // Account for padding float xpad = (float)(getPaddingLeft() + getPaddingRight()); float ypad = (float)(getPaddingTop() + getPaddingBottom()); // Account for the label if (mShowText) xpad += mTextWidth; float ww = (float)w - xpad; float hh = (float)h - ypad; // Figure out how big we can make. float diameter = Math.min(ww, hh);
you want your custom view to be dependent the layout constraints provided by the parent • Input values are stored as packed integers (use methods of View.MeasureSpec to unpack the information) • When calculations are done call: setMeasuredDimension(int width, int height) int mode = MeasureSpec.getMode(widthMeasureSpec) int size = MeasureSpec.getSize(widthMeasureSpec)
View it’s used on. android:layout_gravity Gravity of the View or Layout in its parent. Note: everything with layout_ effects the outside. android:layout_weight Size ratio between multiple views. Example: one view takes 3/4 of the screen and other 1/4. Note: You have to set the height or width to 0dp.
is not used? long poll HTTP? Create a websocket? Custom background service? Google Cloud Messaging. Enables to send downstream messages (from servers to GCM-enabled client apps) Handles all aspects of queueing of messages and delivery to the target client app.
the Google Play Services). TCP client socket receives message >> data parsed >> packed into an intent >> broadcasted >> broadcast receiver catches the broadcast >> message received Could contain 4kb of payload data
references to: • a class that is referenced only in the AndroidManifest. xml file • a method called from JNI • dynamically referenced fields and methods Note: if you are going to use 3rd party error reporting or want to rely on stacktrace for debugging you need to configure Proguard
application so you could use newer features in older versions. Adding to project (Gradle): com.android.support:{name}:22.1.0 v4 Support Library includes the largest set of APIs v7 appcompat library (depends on v4 support) Action Bar, material design (partial)
information inside cards that have a consistent look) v7 gridlayout library GridLayout class (allows to arrange user interface elements using a grid of rectangular cells) v7 mediarouter library Routing of streams to external screens, speakers, and other destination devices
prominent colors from an image) v7 recyclerview library RecyclerView widget (for displaying large data sets). v13 Support Library Like v4 but with less content v17 Leanback Library Supports building user interfaces on TV devices.
DEBUG, VERBOSE. • Debug logs stripped at runtime. • System.out.println() redirected to Log.i() • Apps can not read each other’s logs (unless a system app or root user). Log.v(TAG, "index=" + i);