Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: laying out a simple stack of boxes?
    primarykey
    data
    text
    <p>This should be easy, but for the life of me I cannot figure it out. I want to make a flud stack of boxes, as in this picture:</p> <pre><code>+------------------+ | +------o-------+ | | | Banner | | | +------o-------+ | | | Buttons | | | | | | | +------o-------+ | | | | | | | | | | | ViewFlipper | | | | | | | | | | | | | | | | | | | +------o-------+ | | | Buttons | | | +------o-------+ | | | Footer | | | +------o-------+ | +------------------+ </code></pre> <p>Every box - including the outer one - represents a Layout containing other widgets (or even, a lone widget). The outer box matches the device's width and height. The width and height of the stack must match the outer container. The edges of the boxes are glued to each other and to the top and bottom edges of the container, as indicated by the 'o's. All the inner layouts wrap their content tightly, except the largest - a ViewFlipper - which contains a scrollable listbox and can expand or contract as needed. The number of boxes is not important, as long as it is four or more. </p> <p>The ViewFlipper contains a number of vertical LinearLayouts with width/height=fillparent (where my understanding is that the parent is the ViewFlipper).</p> <p>In my attempts so far, I have had some success with an outer RelativeLayout and stitching the edges of the internal boxes with: <code>android:layout_below="@+id/former_box</code> and <code>android:layout_above="@+id/following_box</code>, but it is an instable situation in which the boxes start acting weird (such as the second one covering entirely the others, etc.) every time I change the design (by, for instance, inserting another intermidiate box). Please note, that this is a design-time layout, no fancy dynamic run-time rearrangements are involved.</p> <p>I am now experimenting with TableLayout (a single column) with basically no joy worth reporting. I am obviously not an Android expert, but still. What is the best way to do this?</p> <p><strong>Edit - insert actual code</strong> Since it appears that omitting the actual code fogged the issue (I hoped it would clarify it, my mistake) I am inserting the working version here. You will notice it lacks the banner and footer. As mentioned above, every time I try to insert additional boxes it blows up on me - circular references starring often.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_margin="0dip" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".TomActivity" &gt; &lt;RelativeLayout android:id="@+id/spinnerbox" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:onClick="left" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/leftarrow" android:background="#888888" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:minHeight="0dip" android:minWidth="0dip" android:layout_alignParentLeft="true" android:onClick="left" android:text="Button" /&gt; &lt;TextView android:id="@+id/spintitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/leftarrow" android:layout_toLeftOf="@+id/rightarrow" android:layout_centerInParent="true" android:layout_toEndOf="@+id/leftarrow" android:layout_toStartOf="@+id/rightarrow" android:gravity="center" android:text="Label" /&gt; &lt;Button android:id="@+id/rightarrow" android:background="#888888" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:gravity="right" android:minHeight="0dip" android:minWidth="0dip" android:onClick="right" android:text="Button" /&gt; &lt;/RelativeLayout&gt; &lt;ViewFlipper android:id="@+id/view_flipper" android:layout_margin="0dip" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/spinnerbox" android:layout_above="@+id/buttonbox" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:layout_margin="0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" &gt; &lt;ListView android:id="@+id/CoursesView" android:layout_margin="0dip" android:background="#ffffff" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_margin="0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" &gt; &lt;ListView android:id="@+id/FutureCoursesView" android:layout_margin="0dip" android:background="#ffffff" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; &lt;LinearLayout android:layout_margin="0dip" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" &gt; &lt;ListView android:id="@+id/MessagesView" android:layout_margin="0dip" android:background="#ffffff" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" &gt; &lt;/ListView&gt; &lt;/LinearLayout&gt; &lt;/ViewFlipper&gt; &lt;LinearLayout android:id="@+id/buttonbox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:orientation="horizontal" &gt; &lt;Button android:id="@+id/CurrentCoursesButton" android:background="#888888" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /&gt; &lt;Button android:id="@+id/FutureCoursesButton" android:background="#888888" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /&gt; &lt;Button android:id="@+id/UnreadMessagesButton" android:background="#888888" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Button" /&gt; &lt;Button android:id="@+id/RefreshButton" android:background="#888888" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="refreshAll" android:text="Button" /&gt; &lt;Button android:id="@+id/LogoffButton" android:background="#888888" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:onClick="logOff" android:text="Button" /&gt; &lt;/LinearLayout&gt; &lt;/RelativeLayout&gt; </code></pre> <p>Cheers,</p> <p><em><strong>Edited to show the layout more clearly and give info on the rationale</em></strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload