Android Programming In Kotlin: Bias & Chains
Written by Mike James   
Monday, 08 October 2018
Article Index
Android Programming In Kotlin: Bias & Chains
Chains
Packing

To get a packed column is more difficult because the chain icon only controls the first chain that a component is in. At the time of writing the only way to set packed on the columns is to edit the XML file.

The chain style is controlled by the first component in the chain. If you look at the XML for the first button in the first row you will see:

app:layout_constraintHorizontal_chainStyle="packed"

This is responsible for setting the first row to packed layout. To set the first column to packed you have to change the XML to read:

app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintVertical_chainStyle="packed"/> 

If you do this you will see the first column in packed format:

bias14

You have to change the XML for the button at the top of the second row and at the top third row to read:

 app:layout_constraintVertical_chainStyle="packed"/>

If you change the top row button’s XML correctly you should see a packed array of buttons:

bias15

The big problem now is that to position the grid of Buttons you have to adjust the bias settings of the first button in each row, which sets the horizontal bias for that row, and the settings of the first button in each column, which sets the vertical bias. There is no single setting that will position the entire grid, and this doesn’t make positioning easy.

What about adding the tenth Button?

It could have been added to the first column but it is just as easy to add it now and set a constraint from the bottom of the last Button in the first column and from the right and left side of the button:

bias16

Summary of Chapter

Italics indicate material in chapter but not in article.

 

  • The ConstraintLayout is the layout of the future and the new Layout Editor was created to work best with it.

  • There are two automatic constraint tools – Autoconnect which works out constraints for a single component, and Infer Constraints which works out any missing constraints for the entire layout. Neither tool is currently particularly useful.

  • You can clear all of the constraints in a layout, or just those on a single component or a constraint at a time.

  • Constraints can be applied from a component to the parent container and these act like absolute positioning.

  • You can set default margins to make positioning components more regular.

  • Components can be positioned relative to another component.

  • You cannot set negative margins.

  • You can align text baselines.

  • Bias constraints allow you to set positions that divide the space available in a specified proportion.

  • Chains provide some of the features of a LinearLayout. For example, you can use a chain to distribute components across the available space.

  • Guidelines can be added to a layout and components can be positioned relative to them, even though they don’t appear in the final layout.

  • Groups can be created which allow you to set the visibility of all of the components in one go.

  • You can set the size of a component absolutely or to be determined by the content. In addition, you can allow a pair of constraints to determine the size.

  • An Aspect Ratio Constraint can set one dimension as the ratio of another.

  • A Barrier is a smart guideline that tracks a specified group of components and is positioned at the most extreme edge of the group in a specified direction. You can position other components relative to the Barrier.

 

 

Android Programming In Kotlin
Starting with an App

Covers Android Studio 3 and Constraint Layout.

Is now available as a print book:

coverKotlinsmall

Buy from: Amazon

Contents

  1. Getting Started With Android Studio 3
  2. The Activity And The UI
        Extract: Activity & UI  
  3. Building The UI and a Calculator App
        Extract: A First App
  4. Android Events
  5. Basic Controls
        Extract Basic Controls
        Extract More Controls ***NEW!
  6. Layout Containers
        Extract Layouts - LinearLayout
  7. The ConstraintLayout 
        Extract Bias & Chains
  8. Programming The UI
        Extract Programming the UI
        Extract Layouts and Autonaming Components
  9. Menus & The Action Bar
  10. Menus, Context & Popup
  11. Resources
        Extract Conditional Resources
  12. Beginning Bitmap Graphics
        Extract Animation
  13. Staying Alive! Lifecycle & State
        Extract  State Managment
  14. Spinners
  15. Pickers
  16. ListView And Adapters
  17. Android The Kotlin Way

If you are interested in creating custom template also see:

Custom Projects In Android Studio

Androidgears

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

kotlin book

 

Comments




or email your comment to: comments@i-programmer.info

<ASIN:1871962544>

<ASIN:1871962536>



Last Updated ( Saturday, 13 October 2018 )