n00b layouting woes

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

n00b layouting woes

Postby ZilverZurfarn » Mon Mar 30, 2009 11:03 am

OK, First post - go gently with me! :)
Here's the deal: I want a pretty static layout with a small frame on top (filling the screen horisontally), a button at the bottom of the screen (again filling the screen horisontally) and, occupying whatever remains between these 2, a scrolling view with a bunch of radio buttons.
So, at all times I want the top panel (with some textviews in it) and the bottom panel to be visible at the top and bottom respectively. What's left is given to the scroll view with the radio button group.
I start with a LinearLayout (fillparent both ways) containing 3 linearlayout, one for each screen part.
The top (wrapcontent vertically) contains 2 textviews, the lower (wrapcontent vertically) contains the button, and the middle (fillparent vertically) a scrollview. The scrollview in turn contains a radiogroup with radiobuttons.
However, the middle LinearLayout occupies all vertical space below the top, pushing the layout containing the button off screen.
I've attached a screen shot of how it looks, and how I'd like it to look if it can make my point any clearer.
Of cource I'd like the layout to work in both portrait and landscape mode.

TIA!
/Mats
Attachments
sc.png
sc.png (35.94 KiB) Viewed 663 times
ZilverZurfarn
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 30, 2009 9:50 am
Location: Sweden

Top

Postby WarrenFaith » Thu Apr 02, 2009 12:44 pm

This should work...
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout android:orientation="vertical"
  2.  
  3.    android:layout_width="wrap_content"
  4.  
  5.    android:layout_height="wrap_content">
  6.  
  7.        <ScrollView>
  8.  
  9.           .....
  10.  
  11.        </ScrollView>
  12.  
  13.         <RelativeLayout android:orientation="vertical"
  14.  
  15.             android:layout_width="fill_parent"
  16.  
  17.             android:layout_height="fill_parent"
  18.  
  19.             android:gravity="bottom">
  20.  
  21.             <Button />
  22.  
  23.         </RelativeLayout>
  24.  
  25. </LinearLayout>
Parsed in 0.002 seconds, using GeSHi 1.0.8.4
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby ZilverZurfarn » Thu Apr 02, 2009 12:51 pm

Thank you - I'll give it a try. All these layouts are pretty confusing - even with many decades of software develoment under my belt. From a quick glance, I see no "top frame" for my static header in your sample XML, but I guess I can just put a TextView inside the outer LinearLayout, before the ScrollView

Thanks!
/Mats
ZilverZurfarn
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 30, 2009 9:50 am
Location: Sweden

Postby ZilverZurfarn » Fri Apr 03, 2009 1:39 pm

:cry: Nope, that didn't do it - The top TextView is there, as the ScrooView, but the button is nowhere to be seen. If I reduce the # of radiobuttons inside the scroll view, the button becomes visible again. So it seems like the scroll view takes all of the screen from the textview down to the bottom of the screen as needed, and pushes whatever is "below" it off screen. More ideas?

TIA!
/Mats

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2.  
  3.    android:orientation="vertical"
  4.  
  5.    android:layout_height="wrap_content" android:layout_width="fill_parent">
  6.  
  7.         <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="This text view should act as header  " />
  8.  
  9.         <ScrollView android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
  10.  
  11.                 <RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
  12.  
  13.                         <RadioButton android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
  14.  
  15.                         <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
  16.  
  17.                         <!-- Lots of more radiobuttons here -->
  18.  
  19.                         <RadioButton android:id="@+id/RadioButton11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />              
  20.  
  21.                 </RadioGroup>
  22.  
  23.         </ScrollView>
  24.  
  25.         <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_gravity="bottom" android:layout_height="fill_parent" android:layout_width="fill_parent" android:orientation="vertical">
  26.  
  27. <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="A button that should always be at the bottom"/>
  28.  
  29. </RelativeLayout>
  30.  
  31. </LinearLayout>
  32.  
  33.  
Parsed in 0.005 seconds, using GeSHi 1.0.8.4
Attachments
sc.png
No button... :(
sc.png (27.6 KiB) Viewed 631 times
ZilverZurfarn
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 30, 2009 9:50 am
Location: Sweden

Postby WarrenFaith » Tue Apr 07, 2009 8:33 am

Ok, I got the solution and wrote a short blog entry about it
:arrow: Layout technics: Static elements below ScrollView
WarrenFaith
Moderator
Moderator
 
Posts: 227
Joined: Fri Mar 13, 2009 10:59 am
Location: Berlin, Germany

Postby ZilverZurfarn » Tue Apr 07, 2009 9:09 am

w00t! :) It really works - in both portrait and landscape mode.
One thing tho - If the scrollview contains just a few items, the button "floats up" to align with the bottom of the ScrollView, instead of remaining at the bottom of the screen.
Thanks for your tutorial.

/Mats
Attachments
sc2.png
sc2.png (64.27 KiB) Viewed 610 times
sc1.png
sc1.png (49.48 KiB) Viewed 610 times
ZilverZurfarn
Freshman
Freshman
 
Posts: 4
Joined: Mon Mar 30, 2009 9:50 am
Location: Sweden

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 2 guests