Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

button at the bottom of a LinearLayout

 
Ranch Hand
Posts: 211
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This seems the most simple thing, yet I can figure out how to do it.

In a LinearLayout, I have a Button and a class MyView that extends View. MyView occupies the space not used by the Button and just does some drawing in it's onDraw method.



It works ok, but I'd like the button at the bottom of the screen, despite the fact that it's declared before MyView in the xml.

Google brings loads of hits on how to do this, many of which must surely be way to complicated for such a simple problem. I've spent ages messing around with layout_weight, layout_gravity and various other attributes.

What is the simplest & cleanest way to achieve this?

Regards
Richard
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'd like the button at the bottom of the screen, despite the fact that it's declared before MyView in the xml.


What are you trying to accomplish by that? LinearLayout displays views in the order they're defined. If you want to change that order, alter the layout file accordingly.
 
Richard Hayward
Ranch Hand
Posts: 211
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ulf

Ulf Dittmer wrote:
What are you trying to accomplish by that?



I did that because I want MyView to take all the remaining space once the Button has been created. If I reverse the order and declare MyView first, it seems to occupy all available screen space and the button cannot be seen.

 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then you are using the wrong layout. Use a RelativeLayout with the custom view set to above the button and the button set to align with the parents bottom
 
Richard Hayward
Ranch Hand
Posts: 211
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steve Luke wrote:Then you are using the wrong layout. Use a RelativeLayout with the custom view set to above the button and the button set to align with the parents bottom



But if I do that,



then the button is at the bottom, but MyView takes all the screen space, I can see it even behind (or maybe on top of), the button.
Changing MyView's layout_height attribute to either "fill_parent" or "wrap_content" still gives the same result.

 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should put the button at the top of the layout file so it is sized and placed first. You will need to give the button an id. Then you use the correct layout attribute to align the custom view above the button

I forget the correct layout attribute to use but if you look up the api for RelativeLayout it should be clear.
 
Richard Hayward
Ranch Hand
Posts: 211
13
VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve & Ulf,

Thanks for your help. I have it working now:



Above uses a SeekBar, instead of a Button but the problem & its solution is the same.

Richard
 
My first bit of advice is that if you are going to be a mime, you shouldn't talk. Even the tiny ad is nodding:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic