Flex Pasta » Flex 4.5: Spark TileLayout Finally Pays off for Multi-Screen Apps

Flex 4.5: Spark TileLayout Finally Pays off for Multi-Screen Apps

Consider from the beginning of Flex, there have always been 4 layout types inside the SDK: Absolute, Horizontal, Vertical, and Tile.  Yes, tile layout(formerly the tilelist in 3.5), the much forgotten child, has been given new life in the Flex 4.5 SDK.  For the most part in applications, I never really had a use for a tile layout.  Enter Flex 4.5 and the multitude of different screen sizes that now exist for mobile applications.  For more larger mobile applications, the home screen component usually consists of some sort of navigation.  For example, icons tiled in a scrollable list:

Tile Layout DroidTile Layout Samsung Tab

Tile layout makes it easy to have an icon screen that flows among many different screen sizes, without any coding changes.  The same code generated the two screens above.  One showing the Motorola Droid and the other is the Samsung Tab.  The tile layout automatically takes advantage of the space given to it and lays out the icons to get the maximum utilization of the space.

Here is a live example on the Droid.  Notice that TileLayout automatically repositions the icons when the phone changes from portrait to landscape mode.

Check out how simple the code is to accomplish a tile layout.

<?xml version=”1.0″ encoding=”utf-8″?>

<s:View xmlns:fx=”http://ns.adobe.com/mxml/2009

xmlns:s=”library://ns.adobe.com/flex/spark” title=”Tile Layout Droid>

<s:layout>

<s:VerticalLayout horizontalAlign=”center” paddingLeft=”10” paddingRight=”10/>

</s:layout>

<s:List itemRenderer=”ir.TileIR” width=”100%>

<s:layout>

<s:TileLayout paddingLeft=”5” paddingRight=”5” horizontalGap=”5” verticalGap=”20” columnAlign=”justifyUsingWidth/>

</s:layout>

<s:dataProvider>

<s:ArrayCollection>

<fx:Object label=”Gmail” icon=”@Embed(source=’/assets/icon1.png’)/>

<fx:Object label=”Youtube” icon=”@Embed(source=’/assets/icon2.jpg’)/>

<fx:Object label=”iTunes” icon=”@Embed(source=’/assets/icon3.png’)/>

<fx:Object label=”Tour de Flex” icon=”@Embed(source=’/assets/icon4.png’)/>

<fx:Object label=”Adobe” icon=”@Embed(source=’/assets/icon5.jpg’)/>

<fx:Object label=”RSS Feed” icon=”@Embed(source=’/assets/icon6.png’)/>

</s:ArrayCollection>

</s:dataProvider>

</s:List>

</s:View>

5 Comments

  • 1. Mitchp replies at 18th May 2011, 4:32 pm :

    Hi Brian,
    I couldn’t find any contact info but I wanted to let you know about a program at the developer community site I work for. It’s called the Most Valuable Blogger program and I’d like to invite you if you’re interested in learning more. Send me an email and I’ll give you the details.

  • 2. Cyianite replies at 30th June 2011, 6:12 am :

    Hi, can I see the running sample of this? I want to run it here in my android to see if its smooth and responsive… Thanks

  • 3. Andy replies at 28th July 2011, 8:47 am :

    This is great but your forgot to post the code for the ItemRenderer (ir.TileIR).

    I know that with lists on mobile devices we should use the new LabelItemRenderer or IconItemRenderer, but what about TileLayouts? Should we use those same ones? Can’t find any documentation about it…

    Thanks and please post the code for your renderer if you can :-)

  • 4. Brian Telintelo replies at 1st August 2011, 11:27 am :

    Andy,

    The item renderer I dont have anymore, but it was something like this:

    itemRenderer
    VGroup
    Image/
    HRule/
    Text/
    /VGroup
    /itemRenderer

  • 5. mahesh replies at 2nd December 2011, 4:34 am :

    Hello,
    i am building a list with images in it, but the images must load from xml file, so how can i get that image files into list components please guide me, I will be very thank full to you.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <blockquote cite=""> <code> <em> <strong>