John Patrick Given

Ruby, Rails, Javascript, Basketball, & Randomness

Android Layout to Pin Buttons at Bottom of Device

Recently I have jumped into developing an app for the Android mobile platform.  While I do enjoy developing for Android it isn't nearly as nice to work with as the iPhone SDK.

This has nothing to do with the languages (Java vs Objective-C) but has everything to do with Android not providing a tool like Interface Designer.

The other day I had to figure out how to pin buttons to the bottom an Android device screen with scrollable content under it.  This is something you would think would be simple to do and reasonably well documented.  Well, it isn't.  In iOS (iPhone) you just drag your widget onto your stage and place it at the bottom.  In Android world you tinker with XML file layouts trying something, then building, trying again, building again, until you get your desired result.

Anyway, I finally figured it out and thought I would share it.

I created a Gist over at GitHub showing the code.  You can look at it here.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
> 
<!-- ScrollView only accepts one child. -->
<LinearLayout
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
> 
<!-- START contents of scroll go here --> 


<!-- END contents of scroll go here --> 
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
> 
<!-- START Menu Buttons --> 

<!-- END Menu Buttons -->
</LinearLayout>
</LinearLayout>


Comments (0)

Leave a comment...

The Fine Print

Hi there. My name is J.P. and I write web based software for a living. My real web site is located here. I tweet about stuff here. I scrobble music occassionally here.

This is my Posterous. I'm a terrible writer. Don't judge me.