AttributeSet attrs) CREATE FROM XML View(Context context, AttributeSet attrs, int defStyleAttr) CREATE FROM XML WITH A STYLE FROM A THEME ATTRIBUTE View(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) CREATE FROM XML WITH A STYLE FROM A THEME ATTRIBUTE OR STYLE RESOURCE A DEEP DIVE INTO ANDROID VIEW CONSTRUCTORS @DANLEW42
a child tells its parent how it wants to be laid out. MarginLayoutParams LinearLayout.LayoutParams 1Child defines LayoutParams in XML or Java getLayoutParams()
constraints to children child.measure() int = { mode | size } AT_MOST X → Be any size up to X EXACTLY X → Be exactly X UNSPECIFIED → No constraints 1 2 Child defines LayoutParams in XML or Java Parent calculates MeasureSpecs and passes to child.measure()
resolveSize(int size, int measureSpec) CHILD PARENT setMeasuredDimension() 1 2 3 Child defines LayoutParams in XML or Java Parent calculates MeasureSpecs and passes to child.measure() Child calculates width/height; setMeasuredDimension() getMeasuredWidth() getMeasuredHeight()
onMeasure() onLayout() onDraw() YES YES NO HAVE TO MEASURE EACH CHILD: child.measure() (ABSTRACT) HAVE TO LAYOUT EACH CHILD: child.layout() DOES NOT DRAW BY DEFAULT setWillNotDraw
Performance https://youtu.be/zK2i7ivzK7M Taming Android UIs with Eric Burke of Square https://youtu.be/ jF6Ad4GYjRU Custom Layouts on Android http://lucasr.org/2014/05/12/custom- layouts-on-android/ Layout traversals on Android https://youtu.be/sdkcuvZCh1U Custom View Groups https://sriramramani.wordpress.com/ 2015/05/06/custom-viewgroups/ 44
android-shaders-filters Don’t Fear the Canvas https://youtu.be/KH8Ldp39TUk Custom drawable states in Android http://charlesharley.com/2012/ programming/custom-drawable-states-in-android Custom Drawables http://ryanharter.com/blog/2015/04/03/ custom-drawables/ The Magic World of Drawables https://youtu.be/1YjB1uUfxgE Hardware Acceleration https://developer.android.com/guide/ topics/graphics/hardware-accel.html 47