Rounded corners in Android elements

Doing Android development makes me appreciate CSS much more.

When it comes to web development, I’m one of those people who tries his best to avoid front end development. There’s something about writing HTML and CSS that I find to be tedious and I never really enjoyed writing front end code.

But man, building out UI’s in Android development is even more tedious. I feel like all of my posts related to Android development is me just complaining about how inconvenient Android development is ?

In most UI’s for applications, whether it be web applications or mobile applications, it’s common to have bordered radiuses with box shadows for containers. For example, a container that looks like this

the CSS for a container above would look something like:

It’s pretty simple right? In the CSS, we can define everything we need: width, height, background-color, border and the border radius, and even the box shadow.

Below is the first-round-go attempt and producing in Android XML.

And… then we try to add some more property like android:border or android:border_radius and we get nothing.

To add the borders and border radiuses, we must add a custom drawable, define custom shapes with properties in that drawable, and add that drawable as a background of our LinearLayout. Let’s try this real quick.

And then we add that drawable as a background property to our initial LinearLayout like this.

Personally, I find this really round-about way to add a border, cornered radius, and some shadows around my layout. It seems like a lot of work for something that should be simple, like in our CSS example.

The weird thing is, this type of design where a container or some sort of inner layout having borders, cornered borders, and even shadows are very common in Android apps. Yet, there isn’t a straightforward to implement these sorts of designs in Android.

Perhaps the history of the Android operating system makes it difficult to add these types of features. Or maybe Android developers just don’t care. Maybe Google just doesn’t care. Or worse, perhaps both actually think this isn’t a problem.

I think that if these small improvements were made to the overall development experience (such as making it super easy to add borders and border radiuses to a layout), it would lower the bar for entering the job market as an Android developer, and perhaps encourage more developers from other disciplines to dabble and create more with Android. But then again, I guess most web developers are playing with React Native than thinking about diving into native Android with Java so maybe the previous statement is far-fetched.