Category: studio

42MB to display account information?! Use the Android APK Analyzer to reduce your APK size!

42MB to display account information?! Use the Android APK Analyzer to reduce your APK size!

After looking around at a few Android applications, I realised that there are many developers who don’t know about a great tool in Android Studio — the Android APK Analyzer. I cringe when I go to download a basic application (most of these apps are really simple) and the download size is over 40MB. Whenever I see this, if I have a bit of time, I like to dive into looking at what is bloating the APK.

Looking into these different APKs, I’ve come across some interesting files, from test data to iOS image files, I’ve seen it all. Whilst analyzing these APK files, I’ve noticed some common trends/mistakes that developers make.

I took a look at some of the Top(*) South African Android apps from the Google Play Store and found some interesting information. This blog post aims to show you how easy it is to look into your app and see what the biggest culprit of eating data in your app is. [Disclaimer: I’m not displaying which apps did what — you can figure that out yourself (reach me on Twitter if you want me to help you lower your APK size). ]

The average download size of the Top(*) South African Android app is ~15.3MB — with the largest size sitting at ~ 42MB. 

The largest app on the store had 18.8MB of images and 14MB of native libraries packaged inside.

Okay, so I’ve hopefully gotten your attention. We know our apps are too big, but how do we go about finding this information and improving our apps?

Read More Read More

ConstraintLayout – Guidelines, Barriers, Chains and Groups

ConstraintLayout – Guidelines, Barriers, Chains and Groups

Since my initial blog post about ConstraintLayout, there have been a whole bunch of new features added (and lots of improvements) to ConstraintLayout. This blog post aims to cover some of the new features, namely Guidelines, Barriers, Chains and Groups.

Some of these features require using Android Studio 3.0 Beta 5 and the beta version of ConstraintLayout. In order to use the beta version of ConstraintLayout, make sure you have at least the following dependency in your app level build.gradle file:

Guidelines

Guidelines are small visual helpers to design layouts with. Views can be aligned to a guideline which can simplify layouts, especially if you have the same margin values duplicated on a lot of elements.

Guidelines can be specified in dp from start or end of the screen or they can be a percentage of the width of the screen. To cycle through the different guideline modes, you can click the round icon at the top of the guideline.

To create a guideline and use it, see below:

Guidelines in ConstraintLayout
Guidelines in ConstraintLayout

If you are curious as to how a guideline looks in XML, this is what it looks like:

Other views in the layout can then constrain themselves to the guideline.

Barriers

Barriers are one of my favourite features in ConstraintLayout. A barrier is an invisible view that contains reference to the views that you wish to use to form a “barrier” against. If one of the views grows, the barrier will adjust its size to the largest height or width of the referenced items. Barriers can be vertical or horizontal and can be created to the top, bottom, left or right of the referenced views. Other views can then constrain themselves to the barrier.

Below is an example of creating a barrier from two views and constraining a view to it. As you can see, adjusting the size of the TextView, the barrier adjusts its size and the constrained view moves.

Barriers in ConstraintLayout
Barriers in ConstraintLayout

If you are curious as to how this is created, this is what it looks like in XML:

The property app:constraint_referenced_ids contains a list of view ids that will form the barrier.

Chains

Chains allow you to control the space between elements and how the elements use the space. To create a chain, select the elements that you want to form part of the chain, and then right click – “Chain” – “Create Horizontal/Vertical Chain”.

Chains in ConstraintLayout Android
ConstraintLayout Chains

You are then able to cycle through the different chain modes. There are four different modes: spread_inside, packed, spread and weighted.

Different Chain Modes in ConstraintLayout

The XML for creating a chain is different in that all the views have the constraints defined on them and the first item in the chain specifies the chainStyle.

Groups

With groups, you can logically group together certain views. Don’t confuse this with normal ViewGroups in Android though. A group in ConstraintLayout only contains references to the view ids and not nesting the views inside a group. With a group, you can set the visibility of all views in the group, by just setting the groups visibility without needing to set every view’s visibility. This is useful for things such as error screens or loading screens where a few elements need to change their visibility at once.

To add a group – see below:

Groups in ConstraintLayout

If you are wondering how this looks in XML, here it is:

The property app:constraint_referenced_ids contains a list of all the view ids that need to be a part of the group.

Practical Example

I wanted to try recreate the Google Play Movies detail screen only using ConstraintLayout to see how much I could build in the UI Editor. The results completely blew me away.

ConstraintLayout Android Example
ConstraintLayout Android Example

For the code relating to this layout, checkout this Github repository.

There are loads more features in ConstraintLayout, so subscribe to the blog to receive updates. Have anything to add? Let me know on Twitter.

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

 

References:

How to create a group of File Templates in Android Studio – Part 3

How to create a group of File Templates in Android Studio – Part 3

In the previous two posts, we looked at creating custom live templates and file templates. I received a question on twitter once I posted the file template tutorial:

Read More Read More

How to create your own Live Templates in Android Studio/IntelliJ – Part 2

How to create your own Live Templates in Android Studio/IntelliJ – Part 2

In the last post we looked at how to create a File Template in Android Studio. In this post we will look at Live Templates and how to make your own.

Live templates are “frequently-used or custom code constructs that you can insert into your source code file quickly, efficiently and accurately.”

Read More Read More

How to make your own File Templates in Android Studio – Part 1

How to make your own File Templates in Android Studio – Part 1

androidstudiofiletemplates

I have recently discovered something which is currently making my life easier at the moment: Custom file templates. What is a file template? A file template is a source file that already contains some code to get you started.

In this example, we are going to look at creating a file template for a RecyclerView adapter implementation which is something I often have to look up when trying to create it.

Read More Read More