as2: Layout

Last revised: 10:45 PM Wednesday, January 29, 2020
Assigned:
  • January 17th, 2020
Due:
  • Part1-2 January 22nd, 2020, 10:00pm
  • Part1-2 Lock January 24th, 2020, 10:00pm
  • Part3-4 January 31th, 2020, 10:00pm
  • Part4 Lock Feb 2nd 2020, 10:00pm
  • Reflection Feb 2nd 2020, 10:00pm

Android Goals:

  • Understand Android layout GUI and XML
  • Familiarize with Android programmatic layout API
  • Understand Android constraints implementation
  • Handle portrait and landscape orientation correctly
  • Handle fixed and variable size container views
  • Learn about Inflators

HCI Goals:

  • Make use of interactor hierarchy
  • Use constraints to create responsive layouts
  • Make use of complex built-in layouts
  • Implement reusable layouts
  • Understand how scrolling works
  • Understand how sizes influence layout

GitGrade links

Classroom Summary

Part 1-2: Accept the Assignment / Turn-in the Assignment

Part 3-4: Accept the Assignment / Turn-in the Assignment

Assignment Description

This is the assignment spec for Layout. Scroll down below part 4 for some development strategies and tips curated from last spring’s students!

In Spring 2019, students spent about 10 - 12 hours on average on this assignment. It has been modified somewhat since then, but make sure that you are getting started early, as this can quickly become one of the more time-consuming assignments of the quarter.

Introduction to Parts 1 and 2

For parts 1 and 2, you will be building the same layout twice. It should show five images, be scrollable, and look equally nice horizontally and vertically. In addition, you should use constraints to achive this, using the ConstraintLayout we provide in part1.xml.

It should look like this:

Portrait screenshot for parts 1 and 2 Landscape screenshot for parts 1 and 2

For part 1, you will create the desired layout using Android Studio’s built-in layout editor to create the desired layout, using a combination of XML and the GUI.

For part 2, you will create the same layout programatically and using Java syntax to construct view objects and add them to our activity.

The important part of the interactor hierarchy for parts 1 and 2 is shown below:

graph LR W(LinearLayout) --> Status[StatusBar] W --> R[RelativeLayout] R --> S[ScrollView] S --> C[ConstraintLayout] C --> I1[ImageView: borders: vMargin] C --> I2[ImageView: borders: vMargin] C --> I3[ImageView: borders: vMargin] C --> I4[ImageView: borders: vMargin] C --> I5[ImageView: borders: vMargin] R --> B[BottomNav] classDef greenlarge fill:#dbf0db,stroke:#333,stroke-width:2px,font-size:40pt,padding:0px,height:60px,top:1px; classDef bluelarge fill:#99ccff,stroke:#333,stroke-width:4px,font-size:40pt,padding:0px,height:60px,top:1px; class Status,W,S,R,B greenlarge class C,I1,I2,I3,I4,I5 bluelarge

We can represent this same interactor hierarchy visually as so. Note that you will only be adding things inside of ConstraintLayout.

Reference image for parts 1 and 2 showing how each image is staked vertically with vMargin space on every side; below; above; and between images

Note that you will only be configuring the ImageViews as they relate to ConstraintLayout (shown in blue). Also this is simplified from what you would see in LayoutInspector

And this video shows parts 1 and 2 in action:

You may find the following link helpful when working with constraint layouts: “Building a Responsive UI with Constraint Layout” – Note the “Set Size as a ratio” section here

Further details on Part 1

part1.xml can be found in the res/layout directory in Android Studio once the layout project has been opened.

Tasks:

When it comes to layout, working directly with XML can be a pain, especially when there’s several attributes to keep track of on each element. Luckily, Android Studio provides a visual editor which you can use to build your app layout.

For part1.xml, you will accomplish the following:

Part 2

The Part2View starter code can be found in the cse340.layout directory in Android Studio.

In Part2Activity we have set up the basic scaffolding necessary to complete the given layout. For this section you will be instantiating the view objects from Part 1 programmatically.

Note that, although you have been given the list of image names to add to your view, you still need a way to access that image resource programmatically. We do this for you, but you should study how we do this as it will be used in future assignments.

Tasks:

It may be useful to view the interactory hierarchy using Layout Inspector when Part1 is running to understand how to structure things.

Part 3

Note: Remember to accept the as2-layout-part-3-4 assignment and turn-in the assignment when you are done.

The Part3View starter code can be found in the cse340.layout directory in Android Studio. We will create a custom Layout in Part3 that can organize an arbitrary series of Views into a Pinterest like layout. Pinterest is a great example of a high-profile app that can be built with relatively simple layout instructions. For instance, one could imagine breaking the layout into two large vertical columns, then assigning various elements to each one. You will also need to ensure the columns never differ by more than the height of one image.

Screenshot of pinterest layout

To determine which column a photo should go in, we will use “pinterest” ordering. You should track the height of the images in each column and add the next image to the shorter column (or the left if equal). Be careful not to track the height of the Drawables as opposed to the display height of the image. Two photos of the same aspect ratio should affect the column height identically regardless of resolution as they will both have the same size on-screen.

Screenshot of part 3

Screenshot of part 3, landscape Screenshot of part 3, landscape, scrolled down

We will use inflation as well. A LayoutInflater allows us to accept a valid XML file specifying part of an interactor hierarchy convert it into a View object that can be added to the interactor hierarchy you are constructing. The XML/visual editor makes it much easier to build our app layouts, so we can use that to create new layouts, then use an inflater to convert the XML into an object before programmatically appending it to our current app layout.

The interactor hierarchy for Part 3 is shown below. The elements marked in light green should be created using inflation (and the part3_grid.xml file should do this). The elements shown in blue should be created programmatically. Note the switch to LinearLayout to hold the images.

graph LR C[ViewGroup:ConstraintLayout] C --> Column1[ViewGroup:LinearLayout] C --> Column2[ViewGroup:LinearLayout] Column1 --> V1[ImageView:Broccoli] Column1 --> V2[ImageView:Seaweed] Column1 --> V3[...] Column2 --> V4[ImageView:Soup] Column2 --> V5[...] classDef greenlarge fill:#dbf0db,stroke:#333,stroke-width:2px,font-size:40pt,padding:0px,height:60px,top:1px; classDef bluelarge fill:#99ccff,stroke:#333,stroke-width:4px,font-size:40pt,padding:0px,height:60px,top:1px; class C,Column1,Column2 greenlarge class V1,V2,V3,V4,V5 bluelarge

Tasks:

Part 4

The Part4View starter code can be found in the cse340.layout directory in Android Studio.

For part 4, feel free to explore anything pertaining to layout that we have discussed in the past 2 weeks. Your task is to wireframe and recreate an interface from another popular app. For instance: Twitter, Facebook, Instagram, etc. (not Pinterest!)

Your layout must meet the following requirements:

Reflection

For this part, you will submit your reflection on this assignment to Gradescope. The responses to each question should be kept separate from each other.

  1. Please include the following for Part4 in this reflection:
    • A screen shot of the interface you are emulating
    • Your diagram (hand or computer drawing) of the interactor hierarchy and interface you built. (Note: do not turn in a screen shot of the layout inspector for this). You should turn in something similar to the 2nd and 3rd image on this spec page.
    • A screenshot of the result of your final implementation
  2. Tell us: What did you learn from doing Part4?
  3. Tell us: Was there anything that was surprisingly easy or hard?

Development Strategies

Rotation buttons on emulated android device

These buttons will allow you to rotate the emulated device clockwise/counter-clockwise.

Turn-in

Submission Instructions

Turn-in the Assignment using GitGrade

We will test layout on emulators with different screen sizes. Please use constraint correctly. Don’t just try to match pixels in our sample screenshots.

Grading (40pts)

Layout Rubric: Part 1-2 checkpoint

Final checkpoint

IDE Errors/Warnings you can ignore

NOTE: An error/warning that can be ignored for this assignment cannot be ignored for every assignment. Check IDE notices against specs on per assignment basis.