I Like Walls

03 Aug 2017 | Comments | tags: android instant apps

I have always been told I’m stubborn. And I am. So jumping off this post, I continued doing instant apps stuff and I learnt more things this week.

I haven’t figured out everything, so it is very likely that I will have more of things to say!


'I will just migrate this real quick', said no one ever

28 Jul 2017 | Comments | tags: android instant apps

When Android Studio 3.0 was announced at I/O, I was very keen to try it out. Mostly because of all the cool stuff in it, but also because of more support for instant apps.

We want to continue supporting our instant app, so I thought it’d be a worthy investment to get a headstart and migrate our EAP version to the post-I/O SDK 1.0 version.

Two months later and I am still migrating. 😅

If you are in the same boat as I am (or maybe you are starting out with instant apps?) here are some of the things I have learnt so far:

PS: At one point I gave up on this and shelved the migration for several weeks, hence the “still going on” thing.

PPS: No idea what I am blabbering on about? I talked to Kaushik and Donn about instant apps on Fragmented!


Children, Respect Your Parent(s)

21 Jun 2017 | Comments | tags: android quick tip

I was updating a bit of code the other day that involved dynamically inflating views into a LinearLayout using DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.row_related_property, container, false).

I decided to jump in and update it to use the generated binding’s inflate method: RowRelatedPropertyBinding.inflate(LayoutInflater.from(context)) instead.

This inflated layout has margins set on it’s root, similar to this:

<LinearLayout
        android:orientation="vertical"
        android:layout_marginTop="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <!-- more views here -->
</LinearLayout>

Happy with my changes, I ran the app and immediately noticed a problem. All the views are smooshed together! Show layout bounds tell me that there is no margin being set at all.

My first thought was that generated binding inflation behaves differently. Odd. I looked through the code and it seems to call through to the same method. Weird.

With a little help from my friends (holla Hugo!), I was quickly pointed out the error of my ways. It is important to respect your parent(s)! And by respect I mean pass it on into inflate.

RowRelatedPropertyBinding.inflate(LayoutInflater.from(context), container, false);

One thing I always forget is that any layout_* attribute is an instruction to the parent. Whenever I am reminded of this, I always go “Ah yes of course I knew that”.

The code that generated the screenshot above is in my Sandbox repo.

If you want to read more about views, layouts, and attributes, go ahead and read Ian Lake’s excellent Medium post on the topic.