How do I automatically `layout_below` sequential controls in an Android layout? -


i seem make android layouts have series of controls meant sit 1 below other. example

<relativelayout     android:layout_width="wrap_content"     android:layout_height="wrap_content">      <textview         android:id="@+id/a"/>      <textview         android:id="@+id/b"         android:layout_below="@+id/a"/>      <textview         android:id="@+id/c"         android:layout_below="@+id/b"/>      <textview         android:id="@+id/d"         android:layout_below="@+id/c"/>      <textview         android:id="@+id/e"         android:layout_below="@+id/d"/>  </relativelayout> 

the android:layout_below attributes necessary: without them textviews bunch in same place.

they also, usually, redundant , general source of bugs , tedium. control ids change, controls added , removed, of these strings must edited match properly. illustrate general redundancy of scheme, note how promotes sort of spaghetti:

<relativelayout     android:layout_width="wrap_content"     android:layout_height="wrap_content">      <textview         android:id="@+id/e"         android:layout_below="@+id/d"/>      <textview         android:id="@+id/b"         android:layout_below="@+id/a"/>      <textview         android:id="@+id/d"         android:layout_below="@+id/c"/>      <textview         android:id="@+id/a"/>      <textview         android:id="@+id/c"         android:layout_below="@+id/b"/>  </relativelayout> 

i can see how explicit layout_below directives (and friends such layout_above) useful in circumstances. there no way of configuring layout (e.g. relativelayout) assume each control in series contains should automatically layout_below preceding control?

linearlayout might more suitable kind of ui structure. need, , automatically you. have specify android:orientation can either vertical or horizontal.

more information on linearlayout can found here.

all children of linearlayout stacked 1 after other, vertical list have 1 child per row, no matter how wide are, , horizontal list 1 row high (the height of tallest child, plus padding).

here's quick example:

<linearlayout   android:layout_width="wrap_content"   android:layout_height="wrap_content"   android:orientation="vertical">    <textview     android:id="@+id/text_view_a"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="hey, i'm textview a!"/>    <textview     android:id="@+id/text_view_b"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="hey, i'm textview b!"/>    <textview     android:id="@+id/text_view_c"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:text="hey, i'm textview c!"/>    <!-- ..and on. -->  </linearlayout> 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -