===================[ Layouts ]=================== Layouts are a special kind of View that contain other Views and know how to calculate their positions on the screen (more precisely, in the Window rectangle that an Activity gets from the WindowManager). Layout classes are derived from ViewGroup, which is derived from View. This should give you an idea that Layouts can contain other layouts, in a nested fashion. This is indeed the case. Read: https://developer.android.com/guide/topics/ui/declaring-layout.html There are many ways to achieve the same geometric effects with Layouts. For example, to place some Views such as TextViews, TextEedits, Buttons, etc., in several rows and columns, you may employ a TableLayout or the newer GridLayout (simple examples here: http://www.techotopia.com/index.php/Understanding_Android_Views,_View_Groups_and_Layouts, http://www.techotopia.com/index.php/Working_with_the_Android_GridLayout_in_XML_Layout_Resources) or create a LinearLayout with android:orientation="vertical" and nest several LinearLayouts with android:orientation="horizontal" inside it (we've seen this approach used in the MyRuns app layout that we extracted from its APK in class; see below). RelativeLayout expresses another useful idea about positioning Views: it allows you to specify how they align with each other. For example, you can specify that some View must lie above another, below it, to the left of another, centered vertically in its parent, or aligned against its parent's margin of choice (respectively, android:layout_above="@id/another" android:layout_below="@id/another" android:layout_toLeftOf="@id/another" android:layout_centerVertical = "true" android:layout_alignParentRight="true"). See https://developer.android.com/guide/topics/ui/layout/relative.html Android SDK developers keep introducing new, more flexible layouts. The newer layouts include ConstraintLayout (now the default in the HelloWorld code that the Studio generates for every new project) and CoordinatorLayout, which supports floating buttons and fancy animated action bars. ===================[ ConstraintLayout ]=================== I found these links very useful to understand ConstraintLayout: https://medium.com/exploring-android/exploring-the-new-android-constraintlayout-eed37fe8d8f1 http://www.techotopia.com/index.php/Working_with_ConstraintLayout_Chains_and_Ratios_in_Android_Studio https://medium.com/@loutry/guide-to-constraintlayout-407cd87bc013 (Note that "match_parent" should not be used in ConstraintLayout at all. Negative margins are not supported (which is confusing). Also, it took me forever to figure out that, to respond correctly to the weights property, height or width of elements in the chain must be set to 0dp *and* chain style must be _spread*_, not _packed_! The Studio doesn't warn you if you mix-and-match properties that don't work in ConstraintLayout; so read the www.techotopia.com guide above carefully. I actually bought their ~$20 e-book after finding they had _the only_ clear and detailed explanation of constraint chains, at the URL above.) ==================[ CoordinatorLayout ]================== (You can skip this for now, until you are confident with other layouts and feel the need for fancier behaviors like the collapsing toolbar, swipe gestures, etc.) I found this is a good intro: http://www.androidauthority.com/using-coordinatorlayout-android-apps-703720/ An example of adding a fancy behavior: https://lab.getbase.com/introduction-to-coordinator-layout-on-android/ This has both examples and technical details: http://saulmm.github.io/mastering-coordinator Finally, this will help you experiment with Behaviors: https://medium.com/google-developers/intercepting-everything-with-coordinatorlayout-behaviors-8c6adc140c26 To understand how Android layouts work algorithmically, read https://developer.android.com/guide/topics/ui/how-android-draws.html ==================[ Extracting and analyzing layouts from APKs ]================== When learning layouts, it helps to look at how other people's apps are laid out, and pick up their tricks. Layouts and other XML are stored inside the APK, but in a pre-processed binary format (for efficiency). The inflaters (see below) can only consume this format, not plain XML. So APKtool extracts this format. In class, I ran java -jar apktool_2.2.4.jar d MyRuns-Android-chk1.apk and obtained its activity_main.xml. Compare the screenshot of the app's screen in apktool-example/MyRuns1-screenshot.png and this layout. In it, you can see that the main activity's entire collection of views is wrapped in a , then uses a LinearLayout with android:orientation="vertical" to arrange the elements. Inside that layout, you see first a TextView that holds the label retrieved from "@string/ui_profile_photo" in res/values/strings.xml, i.e., Profile Photo: and then another LinearLayout, this time horizontal, to align the ImageView and the Button side-by-side instead of vertically. Notice where else this trick is used in this layout. Developer Guide encourages reducing the number of layouts for drawing efficiency. So think about how you could redo the same layout with a single RelativeLayout instead of nested linear ones. You will find the full results of disassembly in apktool-example/ ; read https://ibotpeaches.github.io/Apktool/ documentation to interpret them. ==================[ UI without XML layouts ]================== It's important to know that you can create layouts and views entirely from Java, without any XML ("programmatically" or "dynamically"). Look at the examples/NoXmlLayout/ code to see how. Observe that this project has no activity_main.xml layout file! In particular, note that the line "setContentView(R.layout.activity_main);", which normally retrieves the (pre-processed) XML layout by its ID and displays it is commented out. Instead, you manually create all the Views you need such as a Button in this example, and attach them to the Window or to the specific parent views where you want them to go. Instead of specifying the desired height, width, and alignment (gravity) as XML properties of the