0

In my application I want to have sliding menu on the left side just like facebook.

In my previous question I had raised concern regarding the same and thanks to this answer that I could found a way to slide my layout to right using this library. But, I found that, the library does not actually slides the layout, instead it just takes the screenshot and slides the image towards right as the components on the layout are not clickable. And I need those components to be clickable. So, I tried a new way of achieving this by putting the slideout menu on the left by keeping its default visibility to View.GONE and make it visible on click on left top corner "Show/hide Menu" button as shown in figure below.

Layout before:

Layout before clicking Show/hide menu button

Now when I click "Show/Hide Menu" button, the layout is something like-

Layout after:

Layout after clicking Show/Hide Menu Button

As you can see, the layout on the right shrinks and so the button "Some other view" changes its width even if I've set the android:minWidth attribute to those two buttons on the right as well as its parent RelativeLayout.

So my question is, is there any way to shift the layout towards right without the inner components changing their width/layout? So in whatever area is available for my view, it will be filled by whatever portion of the content that can be filled in in that area.

Community
  • 1
  • 1
Rajkiran
  • 15,845
  • 24
  • 74
  • 114
  • I am also facing the same issue.. have you got any solutions yet ? – alchemist Jul 02 '12 at 06:24
  • Not yet. And the solution is not so simple, otherwise people who wrote those libraries would have already implemented that. I personally feel its impossible, because we are not using webview, otherwise, its possible. Would surely post the answer if I find some. – Rajkiran Jul 02 '12 at 09:48
  • I tried to solve it.. and it works for me now. Posting it down as a possible solution. – alchemist Jul 03 '12 at 04:14

2 Answers2

1

This problem can be solved like this:

  • create framelayout with inside: first left menu with 3 buttons and second layout that contains other two buttons (show/hide and other view). This way, the second layout is in front of menu (since it is fill_parent).

  • in onClick of show/hide button perform translate animation: assuming that your menu is 200px wide, move the second layout by 200 to the right.

  • in onAnimationEnd, set margins to the second layout like this: secondLayoutLayoutParams.setMargins(200, 0, -200, 0);

Closing menu is similar: move the second layout to the left by 200 and set all margins to 0.

By setting margins you will avoid button shrinking.

Hope it helps

Tamara
  • 275
  • 1
  • 10
  • Thanks. It worked. Although I **DID NOT USE** FrameLayout, I just set the margins to the right layout at runtime. – Rajkiran Jul 03 '12 at 16:02
1

@Rajkiran - I have a root layout, that contains my left & right layouts.

My right layout has layout_height set to 'match_parent' & layout_widht is also set to 'match_parent'

Now when my left sliding panel appears on button click, I reset the width & height of my right layout programmatically to match the width & height of the root layout.

This perfectly shifts the right layout towards right without the inner components wrapping up.

To change height & width programatically I used this -

                rootLayoutParams = new LayoutParams(rootLayout.getWidth(), rootLayout.getHeight());

                rightLayout.setLayoutParams(rootLayoutParams);

Hope it helps you as well.

alchemist
  • 1,081
  • 12
  • 17
  • The answer you gave is not shifting the layout towards right but it is coming over the left layout. Can you please post the xml? – Rajkiran Jul 03 '12 at 15:47