Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Gmail app achieve it's flat view hierarchy?

I'm attempting to optimize my listitems, when I go into my developer options and turn on "Show Layout Bounds" I noticed that the Gmail app has a completely flat view hierarchy? How is this black magic achieved?

enter image description here

enter image description here

like image 487
android_student Avatar asked May 23 '15 23:05

android_student


People also ask

What is view hierarchy in android?

Hierarchy Viewer is a tool built into Android Device Monitor that allows you to measure the layout speed for each view in your layout hierarchy. It can help you find performance bottlenecks caused by the structure of your view hierarchy.

Which layout is faster in android?

Measurement results: ConstraintLayout is faster As these results show, ConstraintLayout is likely to be more performant than traditional layouts. Moreover, ConstraintLayout has other features that help you build complex and performant layouts, as discussed in the benefits of a ConstraintLayout object section.

What is the best layout to use in Android Studio?

LinearLayout is perfect for displaying views in a single row or column. You can add layout_weights to the child views if you need to specify the space distribution. Use a RelativeLayout, or even better a ConstraintLayout, if you need to position views in relation to siblings views or parent views.

How to check layout performance android?

One tool that provides excellent data about performance is Systrace, which is built into the Android SDK. The Systrace tool allows you to collect and inspect timing information across an entire Android device, allowing you to see when layout performance problems cause performance problems.


2 Answers

They're likely overriding onDraw and drawing directly to the canvas instead of adding views as children.

http://developer.android.com/training/custom-views/custom-drawing.html

like image 72
devnate Avatar answered Sep 17 '22 20:09

devnate


Well, I might be wrong on a few details, but they are using a custom view. A widget, if you want.

Practically, you have a class that extends something, most likely a View, a LinearLayout or a RelativeLayout, than you programmatically add the stuff you need in there and make sure you have methods to acces the stuff from outside, so that when you create a new "thingy", you will be able to give it whatever text or images you want.

In your case, what I would do is a widget that extends LinearLayout and I would add there the image, 3 textViews (name, subject, actual mail) and one more TextView for the date. If you want the star too, that would be one more thing added, an ImageView. You move them around whatever way you want, and that's pretty much it.

If you want some code for that, let me know, I'll give you some more details if you really need.

like image 22
Vlad Avatar answered Sep 19 '22 20:09

Vlad