LinearLayoutICS, another great Class in the support library

In one of my previous blog posts, I mentioned that the Android support libraries are full of hidden treasures. This time it’s all about the LinearLayoutICS class.

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute or by calling the setOrientation() method.

linearlayout

Since Android 4.0 (Ice Cream Sandwich), it is possible to let Android draw dividers between all the child views within a LinearLayout.

clock application

This is a nice feature which saves you some time to implement these dividers yourself, but it’s not available before Android 4.0. Using the LinearLayoutICS ViewGroup from the Android v7 support library (which extends from the native LinearLayout), completely solves this problem for you.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:support="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.internal.widget.LinearLayoutICS
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        support:showDividers="middle"
        support:divider="?attr/dividerHorizontal"
        support:dividerPadding="10dp">

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 1"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 2"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 3"/>

        <Button
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 4"/>

    </android.support.v7.internal.widget.LinearLayoutICS>

</LinearLayout>

And this is the final result:

LinearLayoutICS

Don’t forget to add the support libraries to your project, good luck!