ENTRIES TAGGED "layout"
On both front and back end, the Web challenges conventional wisdom
The Web is different, and I can see why programmers might have little tolerance for the paths it chose, but this time the programmers are wrong. It’s not that the Web is perfect – it certainly has glitches. It’s not that success means something is better. Many terrible things have found broad audiences, and there are infinite levels to the Worse is Better conversations. And of course, the Web doesn’t solve every programming need. Many problems just don’t fit, and that’s fine.
So why is the Web better?
Effectively combine characteristics and qualifiers for optimum layouts
DisplayMetrics Red Flag
A search of GitHub returns more than 42,000 hits for the class name
DisplayMetrics. This is a red flag. Although there are safe and valuable uses for this information, a quick look at the code using this class reveals that most programs query it to determine screen dimensions, using code like this:
DisplayMetrics displaymetrics = new DisplayMetrics();
int i = Math.max(displaymetrics.heightPixels, displaymetrics.widthPixels);
sScreenNailSize = i / 2;
sThumbNailSize = i / 5;
The programs then make decisions about how the program should present its user interface. This is dangerous, because it tempts the programmer to make decisions with awful long-range consequences, when these decisions should be left up to the Android run-time.
How to Break Lots of Apps in One Easy Step
How dangerous is it? Pull up a random app on your Android device, go to the Settings and select Font Size, then select Huge.
Now see how many apps break:
- How many have fixed-size views in their layouts where text overflows its bounds?
- How many “fixed” that bug by setting the font size, and ignoring your preferences?
- How many make incorrect layout decisions where objects don’t quite fit?
- How many lock the app’s UI to a landscape or portrait orientation?
When you make your own decisions, based on screen dimension and other parameters, about how to present the user interface, you enter a danger zone that spawns bugs that can easily escape detection in both automated and manual testing. If bugs are caught late in the game, they create pressure to implement lame fixes.
The Only Way To Win Is Not To Play the Game
Aren’t you forced to make decisions about presentation? The answer is “No.” You should not be asking “How high, how wide, how dense, what font,” etc.
You should let Android ask the questions and make decisions about presentation. The only question, then, is how many answers you need to provide. Using multiple layouts for different configurations, and avoiding fixed values in layouts, you can make a system of layouts and let Android choose which layouts to use for different screen sizes and orientations.
Once used for simple formatting, CSS now dominates the web presentation layer.
Eric Meyer, the author of CSS: The Definitive Guide (and much more) has taught thousands of people CSS through his books, his talks, and his articles. I’ve always enjoyed hearing his take on the state of CSS, as he manages to find combinations of capabilities that make CSS more powerful than I thought it was when I first looked.
We sat down last week to discuss the many huge changes CSS3 is bringing, from improvements to old capabilities to completely new tools for animations, transforms, and layout. The continuous rate of change and the size of the specification are driving him to serialize the next edition of the Definitive Guide, releasing it in pieces. Developers can work from familiar foundations, but reach new destinations. The declarative strength of CSS3 lets you create presentation by describing it, and that style keeps proving more powerful.