Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

hiding views and re-layouting their parent - how?

 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a vertical LinearLayout I have two views. Depending on user actions, I wish to hide the lower view, and have the upper view take up the newly empty space. Hiding and showing the lower view is no problem via addView/removeView, but that doesn't cause the upper view to take up the empty space. Calling requestLayout() and forceLayout() on the parent layout has no effect; what is the magic incantation for a dynamic re-layout?
 
Greenhorn
Posts: 5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use setVisibility

http://developer.android.com/reference/android/view/View.html#setVisibility%28int%29

With the parameter 8 : Gone
Using Gone make the layout invisible and make it taking no space in the parent layout
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for suggestion; unfortunately, it makes no difference, even if followed by requestLayout/forceLayout.

The new height *is* properly taken into account if a re-layout is forced by displaying and hiding a soft keyboard. A follow-on "setVisibility(View.VISIBLE)" is ignored in that case, though.

Any other ideas? Does this sound like a bug?
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still stuck on this. I've tried many combinations of setVisibility(View.GONE), parent.removeView, setMinimumHeight, invalidate, parent.requestLayout() and parent.forceLayout() - the result is alway the same: the bottom view is hidden/gone, but the top view will not take expand to take its place.

What's strange is that there are many posts out on the net where one or the other of the method calls I mentioned are said to achieve this effect; but not on my device, and not on any Android version on the emulator.

The following is the layout I'm using; I want to make the "buttons" LinearLayout disappear under certain circumstances (namely, if a soft keyboard is shown):

(Yes, I know I could be using a RelativeLayout, but that doesn't help with the problem at hand.)
 
Lester Burnham
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the end, I did not get this to work, so I resorted to using 2 different layouts - one with, and one without the buttons. The functionality of the buttons will be provided by the options menu instead.

A strange and disappointing case - everything and everybody says this should work, but I can't there from here.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I am facing exactly the same problem. Have you been able to solve it somehow?

Thanks!
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
+1 here. Views are made invisible, but the relayout does not occur no matter what.

EDIT: solved, obviously worked with some adjustments to the layout.
 
reply
    Bookmark Topic Watch Topic
  • New Topic