<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>BlackBerry Developer Blog &#187; layout</title>
	<atom:link href="http://devblog.blackberry.com/tag/layout/feed/" rel="self" type="application/rss+xml" />
	<link>http://devblog.blackberry.com</link>
	<description></description>
	<lastBuildDate>Fri, 24 May 2013 14:44:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devblog.blackberry.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/9ef0a66c09615fa946c4179662398878?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>BlackBerry Developer Blog &#187; layout</title>
		<link>http://devblog.blackberry.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devblog.blackberry.com/osd.xml" title="BlackBerry Developer Blog" />
	<atom:link rel='hub' href='http://devblog.blackberry.com/?pushpress=hub'/>
		<item>
		<title>BlackBerry 10 UI Layout patterns for HTML5 Applications</title>
		<link>http://devblog.blackberry.com/2013/04/blackberry-10-ui-layout-patterns/</link>
		<comments>http://devblog.blackberry.com/2013/04/blackberry-10-ui-layout-patterns/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 15:18:05 +0000</pubDate>
		<dc:creator>Anzor B.</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Absolute]]></category>
		<category><![CDATA[box]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[Stack]]></category>
		<category><![CDATA[webworks]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=14452</guid>
		<description><![CDATA[Full source code with comments is available at: https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts A typical BlackBerry 10 application consists of a number of full-screen views, containing elements (headers, footers, lists, buttons, etc…) that are stacked to take up available screen estate. This article outlines layout techniques that may be used to create such views in HTML5/WebWorks applications, targeting the [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14452&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Full source code with comments is available at: <a href="https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts" target="_new">https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts</a></p>
<p>A typical BlackBerry 10 application consists of a number of full-screen views, containing elements (headers, footers, lists, buttons, etc…) that are stacked to take up available screen estate.</p>
<p>This article outlines layout techniques that may be used to create such views in HTML5/WebWorks applications, targeting the BlackBerry Z10 and BlackBerry Q10.</p>
<p style="text-align:center;"><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog1.jpg?w=250" /> <img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog-2.jpg?w=250" /></p>
<p>This is a typical vertical stack layout with a header, content and footer. The header and footer typically have a fixed height, while the content section stretches up to fill available space depending on screen size.</p>
<p><span id="more-14452"></span></p>
<ul>
<h3><strong>
<li>Absolute/Fixed layout pattern</li>
<p></strong></h3>
</ul>
<p>The absolute/fixed layout allows developers to position elements anywhere on the screen using x and y coordinates. This is not uncommon in layouts today, and is quite easy to implement as long as the number of root elements (header,content,footer) remains low. The developer is required to provide exact dimensions and positions of all elements so they don’t overlap and appear to be ‘stacked’. As the number of root elements increases &#8211; for example we add a search bar to the root, it’s top value is positioned at (height of header) px, while content top is be positioned at (height of header + height of search bar) px, and so on.</p>
<p>Source with comments here: <a href="https://github.com/anzorb/UI-Layouts/tree/master/absolute" target="_new">https://github.com/anzorb/UI-Layouts/tree/master/absolute</a></p>
<h3><strong>HTML:</strong></h3>
<pre>&lt;body&gt;
    &lt;div id=”container”&gt;
        &lt;header&gt;
             &lt;section id=”search-bar”&gt;&lt;/section&gt;
        &lt;/header&gt;
        &lt;content&gt;&lt;/content&gt;
        &lt;footer&gt;&lt;/footer&gt;
   &lt;/div&gt;
&lt;/body&gt;
&lt;/pre&gt;</pre>
<h3><strong>CSS:</strong></h3>
<pre>/* set all sections to absolute */
body,html,.container{
	width:100%;
	height:100%;
	background: #181818;
	margin:0;
}

/* set all sections to absolute */
header,
.content,
footer{
	position: absolute;
}

/* when absolute, we need to explicitly specify the top and bottom coordinates to fill content in */
.content{
	top:240px;
	bottom:120px;
	width:100%;
	background:#181818;
	/* scrolling properties */
	overflow: scroll;
	-webkit-overflow-scrolling: touch;
}

/* common attributes, such as background color and width to stretch to cover the whole screen */
header,
footer{
	background:#bbbbbb;
	width:100%;
}

/* when using absolute, it makes more sense to place the search bar inside of header */
header {
	top:0;
	height: 220px; /* 100 (search bar) + 120 (self) */
}

/* positioned at the bottom of our container */
footer {
	height:120px;
	bottom:0;
}</pre>
<p><strong><span style="text-decoration:underline;">Pros:</span></strong></p>
<p>Cross-platform (works across 100% of mobile and desktop browsers)</p>
<p><strong><span style="text-decoration:underline;">Cons:</span></strong></p>
<p>Developers are required to provide exact measurements, and number of root elements needs to remain low to avoid manual calculations.</p>
<ul>
<h3><strong>
<li>Stack/Flexible layout pattern</li>
<p></strong></h3>
</ul>
<p>Source: <a href="http://www.html5rocks.com/en/tutorials/flexbox/quick/" target="_new">http://www.html5rocks.com/en/tutorials/flexbox/quick/</a></p>
<p>While targeting smartphone applications, developers often need to stack components to take up the available screen height. Header, content and footer sections appear under one another, with the content section flexible and scrollable if its contents overflow the available height. Other elements, such as the search bar can be inserted into the stack, pushing content down and decreasing the height of any flexible regions automatically.</p>
<p>With flex-box, creating a stack layout is easy as it relies on the browser engine to decide how to position and stretch elements to fill the screen. All elements remain relatively positioned which means we are no longer required to provide top or bottom values, and choose which elements have fixed widths and which are to remain flexible.</p>
<p><strong>Please note:</strong> At the time of writing this article, the flex-box standard has split into ‘old’ flex-box and ‘new’ flex-box. The new flex-box standard support is nearly non-existent or broken in most browsers. Although BlackBerry 10 supports both standards &#8211; I chose to focus on the old flex-box in this article for wider browser support. The concept remains the same – flex-box allows stack layouts for web applications.</p>
<p>Source with comments here: <a href="https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts/box">https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts/box</a></p>
<h3><strong>HTML</strong></h3>
<pre>&lt;body&gt;
    &lt;div id=”container”&gt;
        &lt;header&gt;&lt;/header&gt;
        &lt;section id=”search-bar”&gt;&lt;/section&gt;
        &lt;content&gt;&lt;/content&gt;
        vfooter&gt;&lt;/footer&gt;
   &lt;/div&gt;
&lt;/body&gt;</pre>
<h3><strong>CSS</strong></h3>
<pre>/* set your container's display to -webkit-box */
.container{
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-box-align: stretch;
}

/* setting contents flexibility to 1, ensures that it stretches to fill available space */
.content{
	-webkit-box-flex: 1;
	width:100%;
	background:#181818;
	overflow: scroll;
	-webkit-overflow-scrolling: touch;
}

/* fixed heights for header and footer */
header,
footer{
	background:#bbbbbb;
	height:120px;
	width:100%;
}
/* OR flexible heights thanks to flex-box
header.flexible{
	height: auto;
}</pre>
<p>The -webkit-box-flex: 1; property is the ratio of how much available space is allocated to the element relative to other elements. So if we wanted to have two content sections on top of one another, taking up the same height while remaining flexible and adapting to available screen space, we can add the same property (webkit-box-flex: 1) to our second content section. Since the ratio is 1:1, both will take up the same room, while stretching as available screen estate increases.</p>
<p>The Stack/Flexible layout also simplifies use cases where headers/footers and other elements need to remain flexible. For example in an application that displays news articles the header displays news articles’ titles and may take up anywhere from a single line to 3 lines vertically. Ideally, especially when using gradient we want the header to stretch as to not truncate the text :</p>
<p style="text-align:center;"><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/dev3.jpg?w=250" /><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/stacking-changes-coming-header.png?w=250" /></p>
<p>Developers can also leverage min-height and max-height to tell the renderer how flexible the header will be. Since header is a child of container, and container is flexible, no other properties are required.</p>
<pre>/* this allows header to grow up to 170px, which allows for the use case discussed above */
header{
	max-height:170px;
	line-height:45px;
}</pre>
<p><strong>Pros: </strong></p>
<p>Truly flexible, no exact dimensions are required.</p>
<p>Offers a ‘stack’ layout model to HTML5 developers, not uncommon among Cascades developers.</p>
<p><strong>Cons: </strong></p>
<p>Confusion over new and old flex-box.</p>
<p>Browser support (not supported in IE and Opera).</p>
<p>*Although a library exists that ports functionality to IE 6-9 and Opera 10</p>
<p><a href="https://github.com/doctyper/flexie">https://github.com/doctyper/flexie</a></p>
<h3><strong>Detecting and adapting to Landscape orientation</strong></h3>
<p>Source code here: <a href="https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/UI-Layouts/box/media-queries.css">https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/UI-Layouts/box/media-queries.css</a></p>
<p>The BlackBerry Z10 screen is 720px wide, which means that we have 720px of screen height to work with when the device is in landscape. It is often good practice to resize certain elements such as the header and/or footer to allow for more content. The following example demonstrates how to use CSS Media Queries to increase the amount of content visible when in landscape:</p>
<p style="text-align:center;"><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog3.jpg?w=300" /></p>
<p>Here’s the CSS that makes this possible.</p>
<pre>@media screen and (orientation:landscape){
     header
     ,footer{
	height:90px;
     }
}</pre>
<p>The Landscape orientation media query is triggered when viewport height is less than viewport width. This means that if the device is in portrait, and we pull up the keyboard, landscape orientation will also get triggered, resulting in the rules above applied even though the device is in portrait. This is because the virtual keyboard causes a decrease in the screen height to a point where screen is a few pixels shorter than it is wide. This may be an issue if for example the footer contains wider buttons in landscape. The user will see the buttons get wider as the virtual keyboard pops-up – not the best User Experience.</p>
<p>One way to tackle this is by adding a width property:</p>
<pre>/* detect landscape orientation and device width of 1280px */
@media all and (orientation:landscape) and (width:1280px){
     header
     ,footer{
	height:90px;
     }
}</pre>
<p>This restricts our rule to only be in effect when the screen width (or innerWidth) is 1280, in other words, only if device is really in landscape.</p>
<p>A number of core BlackBerry 10 Applications allow the virtual keyboard to overlay the action bar. This allows for greater screen estate, especially if the application relies on messaging a lot (think BBM for example).</p>
<p>A good practice is to have a minimum height where all elements are displayed, and if height is smaller, begin to hide the elements to allow for more content.</p>
<p>The virtual keyboard is 413px high in portrait and 274px high in landscape.</p>
<p>Remaining space when the keyboard is up:</p>
<p>1280 – 413 = 867px (portrait 1280&#215;720 or 1280&#215;768)</p>
<p>768 – 274 = 494px (landscape 1280&#215;768)</p>
<p>720 – 274 = 446px (landscape 1280&#215;720)</p>
<p>This means we can target 450px as the minimum height in landscape and 870px in portrait.</p>
<p>Using CSS Media Queries, let’s hide the header and footer if height does not exceed 450px/870px:</p>
<pre>/* hide header and footer when available height is shorter than target */
@media 
all and (max-height:870px) and (max-width: 768px), /* portrait 1280x720 and 1280x768 */
all and (max-height:450px) and (width: 1280px) /* landscape */
{
    header,footer{
		display:none;
	}
}</pre>
<table>
<tbody>
<tr>
<td>Before with VKB up – portrait:</td>
<td>After with VKB up – portrait:</td>
</tr>
<tr>
<td><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/landscape-with-vkb-before.png?w=250" /></td>
<td><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog5.png?w=250" /></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td>Before with VKB up – portrait:</td>
<td>After with VKB up – portrait:</td>
</tr>
<tr>
<td><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog6.jpg?w=250" /></td>
<td><img alt="" src="http://rimdevblog.files.wordpress.com/2013/04/devblog7.jpg?w=250" /></td>
</tr>
</tbody>
</table>
<p>CSS Media queries also allow developers to target specific devices, by detecting device height and width. The following rules apply if the device screen is 720&#215;720, making the header and footer shorter to allocate more room to the content section.</p>
<pre>/* detect BlackBerry Q10 and make header and footer shorter for more screen estate  */
@media all and (width:720px) and (height: 720px)
{
    header,
    footer{
            height: 90px;
    }     
}</pre>
<p>Since the BlackBerry Z10 offers 768px of screen height when in landscape, while the Q10 offers 720px, it is often easier to apply the same rules to both, as to provide more content in both cases, without having to maintain two separate sets of rules for each.</p>
<p>Here’s how the above rule can be combined with one mentioned earlier:</p>
<pre>/* detect landscape orientation and Q10 device */
@media 
all and (orientation:landscape) and (width:1280px),
all and (width:720px) and (height: 720px)
{
     header
     ,footer{
	height:90px;
     }
}</pre>
<p>Please note that these CSS queries are designed for the flexible layout model only .There would have to be more rules to make it work with the fixed model, as we are required to provide exact positions changes along with size changes when orientation changes &#8211; another pro for the flexible box model.</p>
<p>In conclusion, it’s worth noting that both code quality and performance improve when leaving the layout tasks to the layout engine (CSS), rather than detecting orientation/screen size using JavaScript and applying classes/style. The stack model has been used by Native developers for quite some time and is finally making a debut to HTML5 and provides an intuitive way to create layouts that adapt across devices with different form factors.</p>
<p>Be sure to check out the full source code here (<a href="https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts">https://github.com/blackberry/BB10-WebWorks-Samples/tree/master/UI-Layouts</a>) and save it for when you are working on the layout of your next BlackBerry 10 application.</p>
<h3><strong>Sources</strong></h3>
<p>QUICK HITS WITH THE FLEXIBLE BOX MODEL by Paul Irish</p>
<p><a href="http://www.html5rocks.com/en/tutorials/flexbox/quick/" target="_new">http://www.html5rocks.com/en/tutorials/flexbox/quick/</a></p>
<p>Media Queries for Standard Devices</p>
<p><a href="http://css-tricks.com/snippets/css/media-queries-for-standard-devices/" target="_new">http://css-tricks.com/snippets/css/media-queries-for-standard-devices/</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/14452/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/14452/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=14452&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2013/04/blackberry-10-ui-layout-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/39587172e747f6f28b4a6ee4a906be0d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">anzorb</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog1.jpg?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog-2.jpg?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/dev3.jpg?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/stacking-changes-coming-header.png?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog3.jpg?w=300" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/landscape-with-vkb-before.png?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog5.png?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog6.jpg?w=250" medium="image" />

		<media:content url="http://rimdevblog.files.wordpress.com/2013/04/devblog7.jpg?w=250" medium="image" />
	</item>
		<item>
		<title>Time well spent: An intuitive interface design is the difference between app success and mediocrity</title>
		<link>http://devblog.blackberry.com/2012/04/end-user-feedback/</link>
		<comments>http://devblog.blackberry.com/2012/04/end-user-feedback/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 19:06:32 +0000</pubDate>
		<dc:creator>Matt W</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[app design]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[end user feedback]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://devblog.blackberry.com/?p=8827</guid>
		<description><![CDATA[A list of tips to consider when guiding layout and design of a BlackBerry app.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=8827&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="text-align:center;"><img class="aligncenter size-full wp-image-8830" src="http://rimdevblog.files.wordpress.com/2012/04/072611_bberry_toronto_1940-2.jpg?w=550&#038;h=367" alt="TITLE_IMAGE" width="550" height="367" /></p>
<p>Nothing is more frustrating than putting countless hours of hard work into your BlackBerry® app, making sure every subroutine is perfect and every millisecond of performance squeezed, only to find out that users are displeased with some aspect of layout or interaction. Speaking from experience, I find that numerous times we all too often dive into architecting and developing the meat and potatoes of an app, leaving the user interface to get created ad hoc. Yet behind every good app there is a great user interface!</p>
<p>Now, you might be saying: &#8220;<em>But Matt! I do think about layout and design – but I can’t design for every user’s tastes.</em>&#8221; While we do typically put some thought into layout and design, I find we (as developers) rarely think about it from an end user’s perspective. We are too close to the project, and end up seeing aspects of the application from a specific view. Think of it this way &#8211; every parent thinks their baby is the cutest ever&#8230;but what do the rest of us think? What a good app developer/designer needs to do is take a step back and look at the design from others’ points of view and, better yet, gather points of view from others.</p>
<p>Nothing helps guide a design better than real world feedback. Take your design and layouts and talk to your peers, your mother, your granddad, or even your future end users (basically anyone that will talk to you.) You can even solicit feedback from a limited beta of your app or use various online solutions such as <a href="http://getsatisfaction.com" target="_new">getsatisfaction.com</a>. Ask your users what they like, what they don’t like, how they would expect things to flow, and so on. Taking this feedback and integrating it into your app will help ensure users are happy &#8211; and happy users mean good BlackBerry App World™ storefront ratings!</p>
<p>If you cannot easily gather end user feedback on the design and flow of your app, here are some other points to keep in mind at the beginning of your project:</p>
<ul>
<li>Keep the user interface and design as simple as possible. Your app should require a user to have little to no instructions in order to get started.</li>
<li>For touch screen devices, ensure proper spacing of objects that a user will interact with. Nothing will frustrate your users more if their touch events are misread.</li>
<li>The layout of the screen should be well used, but not too cluttered. For objects in groups, space them evenly for a clean look.</li>
<li>Make use of menus when required. Menus are great when there are additional options or settings that you want a user to have access to, but don’t want to have them always displayed on screen.</li>
<li>Lastly, remember to keep your app consistent. Every screen within the app should offer a similar user experience in layout, theme and flow. A user should know this is your app regardless of the screen they are looking at.</li>
</ul>
<p>Hopefully you have found these tips useful. If you have your own, please share them in the comments section below or head on over to the <a href="http://supportforums.blackberry.com/t5/Developer-Support-Forums/ct-p/blackberrydev" target="_new">BlackBerry Developer Support</a> forums and post them there.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/8827/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/8827/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=8827&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2012/04/end-user-feedback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/24f0db511856433f3357906c9dfd7476?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mwhiteman</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2012/04/072611_bberry_toronto_1940-2.jpg" medium="image">
			<media:title type="html">TITLE_IMAGE</media:title>
		</media:content>
	</item>
		<item>
		<title>How to use Table View layout</title>
		<link>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/</link>
		<comments>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 22:50:22 +0000</pubDate>
		<dc:creator>Shiladitya S.</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Java Development]]></category>
		<category><![CDATA[cell]]></category>
		<category><![CDATA[field]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[Manager]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://blackberrydev.edstaging.com/?p=553</guid>
		<description><![CDATA[Every layout is unique and highly dependent upon the application using it. However, the basic building block for any complex layout is a cell. Each cell can define its space requirements or share with adjacent cells. If we try to visualize this arrangement it will look much like a table. With TableLayoutManager (full sample code [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=553&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Every layout is unique and highly dependent upon the application using it. However, the basic building block for any complex layout is a cell. Each cell can define its space requirements or share with adjacent cells. If we try to visualize this arrangement it will look much like a table. With TableLayoutManager (<a href="http://www.blackberry.com/knowledgecenterpublic/livelink.exe/How_To_-_Create_a_rich_UI_layout_with_TableLayoutManager.html?func=doc.Fetch&amp;nodeId=1906675&amp;docTitle=How+To+%2D+Create+a+rich+UI+layout+with+TableLayoutManager&amp;vernum=2" target="_self">full sample code here</a>), which can handle fixed or relative cell sizes and allow embedding tables, developers can build almost any layout they want very easily. I am not going to focus today on how to build a layout manager, as there are ample <a href="http://www.blackberry.com/developers" target="_self">BlackBerry® Developer Zone</a>resources on this topic. Instead, I will explore the possibilities of how TableLayoutManager can be used. TableLayoutManager has two constructors:</p>
<p><code>public TableLayoutManager(int columnStyles[], long style)</code></p>
<p><code> </code></p>
<p><code>public TableLayoutManager(int columnStyles[], int columnWidths[], int<br />
horizontalPadding, long style )<span id="more-553"></span><br />
</code></p>
<p><em>columnStyles[] </em>defines the styles for all columns, and the number of this array refers to the number of columns desired in a given row. The different column styles to choose from are listed below:<br />
USE_PREFERRED_SIZE   – Allows the field to use up all the space it needs.<br />
USE_PREFERRED_WIDTH_WITH_MAXIMUM – Allows the field to use up as much space as it needs UP TO a preset maximum. You can specify the maximum for each field by passing in the width in the columnWidths variable.<br />
SPLIT_REMAINING_WIDTH – Columns will use up the remaining width evenly.<br />
FIXED_WIDTH – Sets columns to a fixed width.</p>
<p>The SPLIT_REMAINING_WIDTH style can be thought of as the “this column will utilize all the remaining width of the table” style. So if TableLayoutManager has a column defined as SPLIT_REMAINING_WIDTH in conjunction with Manager.USE_ALL_WIDTH, the column will fill the remaining space. If there are multiple columns defined as SPLIT_REMAINING_WIDTH, they will evenly share that remaining width.</p>
<p><em>style –</em> is the manager style. You can just choose from Manager. HORIZONTAL_SCROLL, Manager.xxxx.</p>
<p><em>columnWidths –</em> if you choose you can specify widths to be used for each field for force particular columns size.</p>
<p><em>horizontalPadding –</em> you can also specify horizontal padding between columns .</p>
<p>As you can see above, it’s pretty easy to define the desired amount of columns. Based on number of fields added to the layout, TableLayoutManager will automatically align them in separate rows to keep the desired number of columns. This can often be a helpful feature, as developers won’t need to know the number of rows their table may have at construction time.</p>
<p>Now let’s explore some views that are possible with TableLayoutManager.</p>
<p><strong>Example 1: Say you are building your next great application that requires cover art to be displayed as a grid like view.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-15.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3140" /></p>
<p><strong><span style="font-weight:normal;">This view has five columns, each of which is a BitmapField and each field will accept focus  . This table can be constructed very easily with TableLayoutManager. Here is a code sample of how I constructed the table:</span></strong></p>
<p><code>TableLayoutManager colFMgr = new TableLayoutManager(new int[]<br />
{<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE<br />
}, Manager.HORIZONTAL_SCROLL);</code></p>
<p><code> </code></p>
<p><code>for(int i= 0;i &lt; images.length;i++) {<br />
colFMgr.add(new BitmapField(images[i],Field.FOCUSABLE));<br />
}<br />
add(colFMgr );</code></p>
<p>If you want a little more control on bitmap sizes and how the layout manager uses each cell size you can use the other constructor to pass in widths for each column.</p>
<p><strong>Example 2: Now say I wanted some text below each image but did not want the text to take primary focus.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-16.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3141" /></p>
<p>As you can see, it’s the same structure as Example 1, but for every five BitmapFields, I would have to add five Label fields and disable focus on the Labels. TableLayoutManager will take care of the layout and ordering.</p>
<p><strong>Example 3: Now consider using a table view where the left column contains an image and right columns contain some textual description with a ‘more’ link.</strong></p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3143" /></p>
<p>Conceptually, the per-row view in wireframe would be an outer table with 2 columns:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg?w=322&#038;h=576" alt="" title="How to use Table View layout" width="322" height="576" class="aligncenter size-full wp-image-3143" /></p>
<p>And an inner table with two columns to host some textual description:</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-18.jpg?w=306&#038;h=103" alt="" title="How to use Table View layout" width="306" height="103" class="aligncenter size-full wp-image-3144" /></p>
<p>The inner table is inserted within the COL 1 of the outer table to get our desired view for a given row. Note that the space alignments are configurable based on the style you choose on the layout manager.</p>
<p><img src="http://rimdevblog.files.wordpress.com/2009/10/original-19.jpg?w=212&#038;h=105" alt="" title="How to use Table View layout" width="212" height="105" class="aligncenter size-full wp-image-3146" /></p>
<p>Now that we have constructed each row, you can keep adding COL 1(flower art bitmap) and COL 2 (inner table) and it will take the form as shown in the Example 3 screen shot. All this translates in very little code using TableLayoutManager:</p>
<p><code>TableLayoutManager outerTable = newTableLayoutManager(new int[]<br />
{<br />
TableLayoutManager.USE_PREFERRED_SIZE,<br />
TableLayoutManager.SPLIT_REMAINING_WIDTH<br />
},0);</code></p>
<p>For constructing the inner table:</p>
<p><code>TableLayoutManager innerTable = new TableLayoutManager(new int[]<br />
{<br />
TableLayoutManager. USE_PREFERRED_SIZE,<br />
TableLayoutManager.USE_PREFERRED_SIZE<br />
}, Manager.USE_ALL_WIDTH);</code></p>
<p>In the second case, USE_ALL_WIDTH causes the table to fill the maximum width space. The first USE_PREFERRED_WIDTH will allow COL 1 to take up the minimum necessary amount of space, and COL 2 will automatically fill to fit. If you want COL 2 to use the minimum size, set COL 1 to SPLIT_REMAINING_WIDTH.</p>
<p>Here’s how to add the fields to the inner table:<br />
<code>innerTable.add(titleField);<br />
innerTable.add(titleField1);<br />
innerTable.add(descriptionField);<br />
innerTable.add(descriptionFieldLink);<br />
innerTable.add(ratingField);<br />
innerTable.add(ratingFieldImage);</code></p>
<p>And how to add a bitmap field to the outer table and add the inner table.<br />
<code>outerTable.add(Bitmap.getBitmapResource("image1.png")));<br />
outerTable.add(innerTable);</code></p>
<p>To add more rows to this table, keep adding bitmaps and inner tables to the outer table. And don’t forget to add the outer table to the Screen!<br />
<code>super.add(colFieldMgrForRow);</code></p>
<p>This is not the only way to build a layout like this. For example, for each row I can use a horizontal layout manager (hfm) with two columns. The second column for this hfm would need a vertical field manager (vfm), for which I need three hfm for each row of text (title, description, rating etc). So really there is no one size fits all for layout management. It’s simply a matter of picking the right one that works for your application.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/rimdevblog.wordpress.com/553/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/rimdevblog.wordpress.com/553/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devblog.blackberry.com&#038;blog=17235680&#038;post=553&#038;subd=rimdevblog&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devblog.blackberry.com/2009/10/how-to-use-table-view-layout/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/849ad61a03a581789c41b1c854ef9bf3?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Shiladitya S.</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-15.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-16.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-17.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-18.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>

		<media:content url="http://rimdevblog.files.wordpress.com/2009/10/original-19.jpg" medium="image">
			<media:title type="html">How to use Table View layout</media:title>
		</media:content>
	</item>
	</channel>
</rss>
