jfeinstein10 / SlidingMenu

An Android library that allows you to easily create applications with slide-in menus. You may use it in your Android apps provided that you cite this project and include the license in your app. Thanks!
Apache License 2.0
11.08k stars 5.04k forks source link

SlideMenu views not filling parent #17

Closed RyanBeuler closed 12 years ago

RyanBeuler commented 12 years ago

I'm running into a weird issue where my 2 slidemenu views (main1 and main2) seem to be wrapping around the test placeholder images I've put in there for the time being instead of matching the parent and filling the entire window.. (see pic below)

When I view each layout xml individually they look totally fine and fill the entire window but when I set them each to contentview and behindcontentview they display the behavior illustrated above.

Here's the main1.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main1" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/bkblue">

<ImageView
    android:contentDescription="@string/desc"
    android:id="@+id/sblogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="70dp"
    android:src="@drawable/sblogo" />

It seems the only way I can get the above and below SlideMenu views to fill the entire screen is if I set the images width attribute to android:layout_width="match_parent".

Is this expected behavior or is there another way I should be going about this?

Here's my current activity code in case it helps:

public class MainActivity extends SlidingActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main1);
    setBehindContentView(R.layout.main2);

    ActionBar actionBar = getSupportActionBar();

    SlidingMenu menu = getSlidingMenu();
    menu.setBehindOffsetRes(R.dimen.actionbar_home_width);
    menu.setBehindScrollScale(0.5f);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.showAbove();   

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setIcon(R.drawable.sblogo);
    actionBar.show();
}
jfeinstein10 commented 12 years ago

Right now that's expected. I haven't done anything to override the width and height that is set in xml. Just change them to match_parent like you said. I should probably do that at some point.

RyanBeuler commented 12 years ago

Gotcha... But then my next question becomes how do I get the actual UI I want displayed without using the menu.setViewAbove methods I was using before that was causing issues with the ActionBar?

For example if I create 2 new xml's to serve as my actual UI's and set them as contentview and behindcontentview like I copied below.... it will solve the wrapping issue but I unfortunately lose the ActionBar again...

setContentView(R.layout.main); setBehindContentView(R.layout.mainbk);

ActionBar actionBar = getSupportActionBar();

SlidingMenu menu = getSlidingMenu(); menu.setViewAbove(getLayoutInflater().inflate(R.layout.main1, null)); menu.setViewBehind(getLayoutInflater().inflate(R.layout.main2, null)); menu.setBehindOffsetRes(R.dimen.actionbar_home_width); menu.setBehindScrollScale(0.5f); menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); menu.showAbove();

Is there another easier way to accomplish what I'm trying to do? Sorry if my questions are dumb btw I'm still relatively new to android development...

jfeinstein10 commented 12 years ago

If you are going to use the Activities that I provide, then do not use menu.setViewAbove and menu.setViewBehind. setContentView and setBehindContentView have the exact functionality that you are asking for and are safe to use. I wrote them for exactly this purpose. In your code above your have 4 different views. You only need 2. If you want to use main1 and main2 then change it to this:

setContentView(R.layout.main1);
setBehindContentView(R.layout.main2);

ActionBar actionBar = getSupportActionBar();

SlidingMenu menu = getSlidingMenu();
menu.setBehindOffsetRes(R.dimen.actionbar_home_width);
menu.setBehindScrollScale(0.5f);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.showAbove();
RyanBeuler commented 12 years ago

Roger that, I guess I was just a bit confused because your included example activity uses...

setContentView(R.layout.pager); setBehindContentView(R.layout.frame);

..and I was trying to figure out how to mimic that example but in a simpler manner without the use of fragments.

So I guess in the meantime I'll go back to using the method you described in the post above and try to turn off the visibility on the imageviews inside the main1 and main2 xml's and inflate some new layouts or xml inside main1 and main2...

Only thing I'm not sure of at that point though is how do you go about referencing main1&2 after you've called getSlideMenu()?

RyanBeuler commented 12 years ago

Nevermind figured it out.