Android Developer Fundamentals V2 PDF

Summary

This document describes Android developer fundamentals, lesson 3, focusing on layouts and resources for the user interface (UI). It covers various view components, view groups, and the layout editor within Android Studio.

Full Transcript

Android Developer Fundamentals V2 Build your first app Lesson 3 Layouts and This Thiswork...

Android Developer Fundamentals V2 Build your first app Lesson 3 Layouts and This Thiswork workisislicensed licensedunderundera aCreative Creative Creative Creative Android Developer Android Developer Fundamentals Fundamentals V2 V2 resources for the Commons Commons Creative Creative Attribution CommonsAttribution Commons Attribution4.0 Attribution4.0 4.0 Commons Commons International 4.0 International International International 1 License License UI License. License. Creative Creative 1.2 Layouts and resources for the UI Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 2 License UI License. Creative Contents Views, view groups, and view hierarchy The layout editor and ConstraintLayout Event handling Resources and measurements Layouts and This work is licensed under a CreativeCreative Creative Commons Attribution4.0 Commons 4.0 International Android Developer Fundamentals V2 resources for the Commons Attribution International 3 License UI License. Creative Views Android Developer Fundamentals V2 4 Everything you see is a view If you look at your mobile device, every user interface element that you see is a View. Views Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 5 License UI License. Creative What is a view? View subclasses are basic user interface building blocks Display text (TextView class), edit text (EditText class) Buttons (Button class), menus, other controls Scrollable (ScrollView, RecyclerView) Show images (ImageView) Group views (ConstraintLayout and LinearLayout) Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 6 License UI License. Creative Examples of view subclasses Button CheckBox EditText RadioButton Slider Switch Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 7 License UI License. Creative View attributes Color, dimensions, positioning May have focus (e.g., selected to receive user input) May be interactive (respond to user clicks) May be visible or not Relationships to other views Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 8 License UI License. Creative Create views and layouts Android Studio layout editor: visual representation of XML XML editor Java code Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 9 License UI License. Creative Android Studio layout editor 1. XML layout file 2. Design and Text tabs 3. Palette pane 4. Component Tree 5. Design and blueprint panes 6. Attributes tab Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 10 License UI License. Creative View defined in XML Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 11 License UI License. Creative View attributes in XML android:="" Example: android:layout_width="match_parent" android:="@/resource_id" Example: android:text="@string/button_label_next" android:="@+id/view_id" Example: android:id="@+id/show_count" Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 12 License UI License. Creative Create View in Java code context In an Activity: TextView myText = new TextView(this); myText.setText("Display this text!"); Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 13 License UI License. Creative What is the context? Context is an interface to global information about an application environment Get the context: Context context = getApplicationContext(); An Activity is its own context: TextView myText = new TextView(this); Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 14 License UI License. Creative Custom views Over 100 (!) different types of views available from the Android system, all children of the View class If necessary, create custom views by subclassing existing views or the View class Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 15 License UI License. Creative ViewGroup and View hierarchy Android Developer Fundamentals V2 16 ViewGroup contains "child" views ConstraintLayout: Positions UI elements using constraint connections to other elements and to the layout edges ScrollView: Contains one element and enables scrolling RecyclerView: Contains a list of elements and enables scrolling by adding and removing elements dynamically Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 17 License UI License. Creative ViewGroups for layouts Layouts are specific types of ViewGroups (subclasses of ViewGroup) contain child views can be in a row, column, grid, table, absolute Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 18 License UI License. Creative Common Layout Classes LinearLayout ConstraintLayout GridLayout TableLayout Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 19 License UI License. Creative Common Layout Classes ConstraintLayout: Connect views with constraints LinearLayout: Horizontal or vertical row RelativeLayout: Child views relative to each other TableLayout: Rows and columns FrameLayout: Shows one child of a stack of children Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 20 License UI License. Creative Class hierarchy vs. layout hierarchy View class-hierarchy is standard object-oriented class inheritance ○ For example, Button is-a TextView is-a View is-an Object ○ Superclass-subclass relationship Layout hierarchy is how views are visually arranged ○ For example, LinearLayout can contain Buttons arranged in a row ○ Parent-child relationship Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 21 License UI License. Creative Hierarchy of viewgroups and views ViewGroup Root view is always a ViewGroup ViewGroup View View View View View Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 22 License UI License. Creative View hierarchy and screen layout Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 23 License UI License. Creative View hierarchy in the layout editor Layouts and This work is licensed under a CreativeCreative resources for the Creative Commons Android Developer Fundamentals V2 Commons Attribution Commons Attribution4.0 International 4.0 International 24 License UI License. Creative Layout created in XML

Use Quizgecko on...
Browser
Browser