Does Android have some equivalent to iPhones struts and springs?

I keep on struggling to find some equivalent to iPhone's struts and springs in Android. And don't say gravity :-)

Well do say gravity, but then explain how I can prevent views being pushed off the screen in LinearLayout or RelativeLayout. Or show me some other layout that allows the screen to be filled without bumping things out of sight.

In iPhone Interface builder I would just set the springs appropriately to have each view take up as much space as is available but no more. This allows iPhone layouts to handle orientation changes real good.

In Android the main approach I read about seems to be to create multiple layout folders like layout-port and layout-land and then replicate XML layout files across them, but that seems highly error prone, and still the only way I can stop get a large custom view from pushing other buttons off the screen is to set its layout_height precisely for a particular screen size and orientation. Given the range of Android displays hitting the market this feels like it's going to be more and more of a pain.

Here's an example:

<LinearLayout xmlns:android=""
    android:orientation="vertical" android:layout_width="fill_parent"
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:text="@string/hello" />
    <ImageView android:id="@+id/imageView1" android:src="@drawable/icon"
        android:layout_height="320dip" android:layout_width="fill_parent"></ImageView>
    <SeekBar android:layout_height="wrap_content" android:id="@+id/seekBar1"

these are all just default widgets. I defy you to find some other way to set the ImageView height so that it fills as much of the screen as possible without knocking the seekbar out of sight. Try setting the Imageview android:layout_height to fill_parent to see what I mean.

I have tried Relative Layouts and Table Layouts, and all sorts of tricks. Maybe I am missing something simple, but I'll be damned if I can find it ...

The only solution I can think of (but have yet to actually try) is to do something in code to detect the screen size and other widgets, but I am loathe to go that route since it seems like there should be a simple XML layout solution.


Try using android:layout_weight while setting the android:layout_width or android:layout_height to 0dp (depending on the parent view's android:orientation value).

There's no better equivalent in Android to what you want to do...

I had similar problem (much more of them to be honest) so I developed SpringLayout: If I understood correctly, then I think I managed to achieve what you wanted (the image takes as much space as possible):

<?xml version="1.0" encoding="utf-8"?>
<org.coderoller.springlayout.SpringLayout xmlns:android=""
    android:background="@android:color/white" >

        android:text="Test" />

        android:src="@drawable/ic_launcher" />

        app:layout_alignParentBottom="true" />


Here is the screenshot

Need Your Help

Setting Div Width Intelligently

javascript jquery css layout html

For a while, I have been trying to find a way to set the width of a &lt;div&gt; according to its content in an attractive way. I want to be able to tell the &lt;div&gt; to have a line break every so

XSL: how to convert this 004 to just 4

xml xslt xslt-1.0

I have some XML that looks like the following: