Android Development

Guowei Lv

3 minute read

Yes, there is documentation and tons of sample apps out there. But they are all in a top down approach, meaning they give you the final result of how to use it first, and never tells you why and what is behind the scenes. I will fix that in this article, and present a bottom up approach which leads to much better and deeper understanding. First, at the bottom of things, we need to define what is ViewModel.

Guowei Lv

2 minute read

It is quite common in Android that we need some expandable widget to show and hide information. This is my first attempt, note that this is only a “sketch”, and I intentionally leave some room for improvement. One interesting detail worth mentioning is how the animation is done. I used the reverse() function to play animation backwards in order to achieve a smooth and continuous feel.

Here is the code:

View Binding Internals

Peek into the internals of view binding

Guowei Lv

1 minute read

I was bored at night so decided to peek into the guts of how Android’s View Binding works. To my suprise the generated code is extremely simple. Imagine you have a list_item.xml file and it looks like this: <LinearLayout> <ImageView android:id="@+id/icon" /> <TextView android:id="@+id/name" /> </LinearLayout> Then the generated class will be like this: public final class ListItemBinding implements ViewBinding { private final LinearLayout rootView; public final ImageView icon; public final TextView name; // Notice: private constructor private ListItemBinding(LinearLayout rootView, ImageView icon, TextView name) { this.

Back to Basics - App Bar

Going back to the very basics of Android development

Guowei Lv

2 minute read

We often hear 3 words: app bar, action bar and tool bar. Let’s make clear of them first: - app bar: the name of the UI element/bar at the top of the app. - action bar: the previous implementation of app bar, comes with some themes by default. But should not really be used anymore. - tool bar: the current implementation of app bar. Should be used in replacement of action bar.