tags:

views:

116

answers:

1

I am working on creating an Action Bar like the one from the new Android UI Patterns and I am running into a bit of trouble. I have a ViewSwitcher with two layouts in it. When the user taps the search button I animate between the two layouts. The problem is that the layouts are different sizes and I can't figure out how to make them take up the same amount of space. Here's what I mean. p.s. forgive the bad art, they are just place holders ;)

The red box is right up against the ViewSwitcher and there is a gap between that and the action bar for this layout:

Gap

but not this one:

No Gap

What I want is to tell the layouts in the ViewSwitcher to be the same size. How can I do this?

A: 

You can try setting android:minHeight on the smaller one to be whatever the height of the larger one is. Or maybe setting it on the ViewSwitcher itself.


Idea:

The ViewSwitcher only lets you add two Views and in your case they are two ViewGroups. You can call View#measure on each of the views you're adding to the ViewSwitcher. It looks like you should use ViewGroup.LayoutParams.WRAP_CONTENT for each parameter to measure. Then you can call View.getMeasuredHeight on each view. What ever is the larger set the smaller view using View#setMinHeight.

Qberticus
The problem that I am having is that I don't know how big the bigger one is. It depends on the size of the `EditText`. I've seen three different sizes on three different phones. :(
CaseyB
I'll try your new suggestion, it's a bit more code heavy though. I was hoping to keep it in the xml.
CaseyB