Saturday, November 19, 2011

This is a test post.

Sometimes you want a layout where you want a spacer view that fills that pushes views to the right of it as far as they can. A common need to do something like this is when you roll your own Action Bar.
The action bar layout with the spacer view highlighted.
Explanation
When working with LinearLayout there's an option to use weights of free space rather than a set amount of space. When the layout measures its children it first sets the fixed sized children. For this layout that's everyone except the spacer view. Then it does another pass to measure the children that will fill dimensions based on their android:layout_weight parameter. Since there's only 1 view with this parameter, it fills up the remaining space.
XML Layout


    
    
    
    
    
    
    


The code that makes this work is the ImageView with the comment on it. @id/SpacerView