Weighted Layouts, 50/100 Days of Code
Adding weight to layouts is a great way to make the most of a device’s display.
There is leftover unused space after layouts render on screen. Adding weights to layouts forces them to utilize this remaining space. This is common in E-mail apps when users compose a new message. The Android website has plenty of information on this topic. You can find my source code for an example project here and a video of my demo at the bottom of the page.
In my demo, I added five TextViews, each styled using custom colors I created using Android Studio project resources.
Using the android:layout_weight XML attribute, I changed the layout weight of each to various values to illustrate the different ways layouts can be used to style an activity. The easiest way to understand how to interpret the values is each value is a fraction of the sum of all the layout weight values. This fraction determines how much of the empty space the layout will use.
For practice, I set each TextView weight to 1 so they each take up a fifth of the screen. Feel free to play with the values and see what you can come up with. The Android website has plenty of information on this topic. You can find my source code for an example project here and a video of my demo at the bottom of the page.
Join the mailing list to see updates like this every week!
Coding Fanatic