вторник, 29 мая 2012 г.

The curious BlinkLayout in Android

Yesterday read some post from blog (http://www.androidzeitgeist.com/) of my Google+ friend Sebastian Kaspari. On the bottom you can see repost.

While reading the source code of Android's LayoutInflater class I found a hidden gem that seems to be quite unnoticed yet. Ladies and gentlemen I present you the mighty BlinkLayout. Views that are placed inside this ViewGroup blink at a rate of 500ms.The BlinkLayout is an inner class of the LayoutInflater and can therefore only be used in a XML layout that will be parsed by a LayoutInflater instance. Due to the implementation it's only possible to use it as root node using the <blink> tag inside a XML layout. It seems like the BlinkLayout is available since Android 4.0 and isn't used in the Android source code I observed. Maybe it was added for debugging reasons and was forgotten later.


The video above shows the BlinkLayout in action using the following layout XML:


     
    

The following snippet was used to inflate the layout and pass it to the activity:
package com.androidzeitgeist.blinklayout;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class BlinkLayoutActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        View view = LayoutInflater.from(this).inflate(R.layout.main_layout, null);
        setContentView(view);
    }
}