Giter VIP home page Giter VIP logo

slidingmenu's Introduction

SlidingMenu (Play Store Demo)

SlidingMenu is an Open Source Android library that allows developers to easily create applications with sliding menus like those made popular in the Google+, YouTube, and Facebook apps. Feel free to use it all you want in your Android apps provided that you cite this project and include the license in your app.

SlidingMenu is currently used in some awesome Android apps. Here's a list of some of them:

If you are using SlidingMenu in your app and would like to be listed here, please let me know via Twitter!

Here's an older video of the example application in this repository : http://youtu.be/8vNaANLHw-c

Also, you can follow the project on Twitter : @SlidingMenu

Setup

  • In Eclipse, just import the library as an Android library project. Project > Clean to generate the binaries you need, like R.java, etc.
  • Then, just add SlidingMenu as a dependency to your existing project and you're good to go!

Setup with ActionBarSherlock

  • Setup as above.
  • Checkout a clean copy of ActionBarSherlock and import into your Eclipse workspace.
  • Add ActionBarSherlock as a dependency to SlidingMenu
  • Go into the SlidingActivities that you plan on using make them extend Sherlock___Activity instead of ___Activity.

How to Integrate this Library into Your Projects

In order to integrate SlidingMenu into your own projects you can do one of two things.

1. You can wrap your Activities in a SlidingMenu by constructing it programmatically (new SlidingMenu(Context context)) and then calling SlidingMenu.attachToActivity(Activity activity, SlidingMenu.SLIDING_WINDOW | SlidingMenu.SLIDING_CONTENT). SLIDING_WINDOW will include the Title/ActionBar in the content section of the SlidingMenu, while SLIDING_CONTENT does not. You can check it out in the example app AttachExample Activity.

2. You can embed the SlidingMenu at the Activity level by making your Activity extend SlidingActivity.

  • In your Activity's onCreate method, you will have to call setContentView, as usual, and also setBehindContentView, which has the same syntax as setContentView. setBehindContentView will place the view in the "behind" portion of the SlidingMenu. You will have access to the getSlidingMenu method so you can customize the SlidingMenu to your liking.
  • If you want to use another library such as ActionBarSherlock, you can just change the SlidingActivities to extend the SherlockActivities instead of the regular Activities.

3. You can use the SlidingMenu view directly in your xml layouts or programmatically in your Java code.

  • This way, you can treat SlidingMenu as you would any other view type and put it in crazy awesome places like in the rows of a ListView.
  • So. Many. Possibilities.

Simple Example

public class SlidingExample extends Activity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(R.string.attach);
		// set the content view
		setContentView(R.layout.content);
		// configure the SlidingMenu
		SlidingMenu menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
		menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
		menu.setShadowWidthRes(R.dimen.shadow_width);
		menu.setShadowDrawable(R.drawable.shadow);
		menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
		menu.setFadeDegree(0.35f);
		menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
		menu.setMenu(R.layout.menu);
	}
    
}

XML Usage

If you decide to use SlidingMenu as a view, you can define it in your xml layouts like this:

<com.jeremyfeinstein.slidingmenu.lib.SlidingMenu
    xmlns:sliding="http://schemas.android.com/apk/res-auto"
    android:id="@+id/slidingmenulayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"
    sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"
    sliding:touchModeAbove="margin|fullscreen"
    sliding:behindOffset="@dimen/YOUR_OFFSET"
    sliding:behindWidth="@dimen/YOUR_WIDTH"
    sliding:behindScrollScale="@dimen/YOUR_SCALE"
    sliding:shadowDrawable="@drawable/YOUR_SHADOW"
    sliding:shadowWidth="@dimen/YOUR_SHADOW_WIDTH"
    sliding:fadeEnabled="true|false"
    sliding:fadeDegree="float"
    sliding:selectorEnabled="true|false"
    sliding:selectorDrawable="@drawable/YOUR_SELECTOR"/>

NOTE : you cannot use both behindOffset and behindWidth. You will get an exception if you try.

  • viewAbove - a reference to the layout that you want to use as the above view of the SlidingMenu
  • viewBehind - a reference to the layout that you want to use as the behind view of the SlidingMenu
  • touchModeAbove - an enum that designates what part of the screen is touchable when the above view is showing. Margin means only the left margin. Fullscreen means the entire screen. Default is margin.
  • behindOffset - a dimension representing the number of pixels that you want the above view to show when the behind view is showing. Default is 0.
  • behindWidth - a dimension representing the width of the behind view. Default is the width of the screen (equivalent to behindOffset = 0).
  • behindScrollScale - a float representing the relationship between the above view scrolling and the behind behind view scrolling. If set to 0.5f, the behind view will scroll 1px for every 2px that the above view scrolls. If set to 1.0f, the behind view will scroll 1px for every 1px that the above view scrolls. And if set to 0.0f, the behind view will never scroll; it will be static. This one is fun to play around with. Default is 0.25f.
  • shadowDrawable - a reference to a drawable to be used as a drop shadow from the above view onto the below view. Default is no shadow for now.
  • shadowWidth - a dimension representing the width of the shadow drawable. Default is 0.
  • fadeEnabled - a boolean representing whether or not the behind view should fade when the SlidingMenu is closing and "un-fade" when opening
  • fadeDegree - a float representing the "amount" of fade. 1.0f would mean fade all the way to black when the SlidingMenu is closed. 0.0f would mean do not fade at all.
  • selectorEnabled - a boolean representing whether or not a selector should be drawn on the left side of the above view showing a selected view on the behind view.
  • selectorDrawable - a reference to a drawable to be used as the selector NOTE : in order to have the selector drawn, you must call SlidingMenu.setSelectedView(View v) with the selected view. Note that this will most likely not work with items in a ListView because of the way that Android recycles item views.

Caveats

  • Your layouts have to be based on a viewgroup, unfortunatly this negates the <merge> optimisations.

Developed By

  • Jeremy Feinstein

License

Copyright 2012-2014 Jeremy Feinstein

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

slidingmenu's People

Contributors

aiwilliams avatar alfthomas avatar atermenji avatar chrisjenx avatar cmoatoto avatar ddrboxman avatar donnfelker avatar huahang avatar ipaulpro avatar jfeinstein10 avatar linuxmotion avatar liruqi avatar matthewlim avatar michaelcspeed avatar robux4 avatar rockodev avatar yccheok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slidingmenu's Issues

SlideMenu views not filling parent

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:

<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();
}

Example doesn't show right info

When I try to run the example, any of the lists don't change the text to show, so they show "Medium Text" in every item of the list. What am I doing wrong?

TouchMode MARGIN does not work on some devices

Hi,

Great work, as mentioned on twitter the MARGIN touch mode does not work on some devices.

Thus far found that this is an issue on Samsung Note, HTC Sensation (coincidently running Gingerbread 2.3.4).
(fyi, FULLSCREEN works on these devices, but of course that breaks the view pager).

I have a few more devices that I will get round to testing it on, If i solve the problem I shall pull request it.

Cheers,
Chris

Transparente Layout

First, very nice work dude

Second, i think i found something weird, it happen when the main layout has trasnparent background and the behind layout is too large, the behind layout overlap the main layout and it looks weird.

For example set android:background="@android:color/transparent" to the main layout, and for behind layout use this:

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="button1" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="button2" />

<Button
    android:id="@+id/behindbutton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="button3" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This is a laaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarge button" />
To fix it, you just need to set a non-transparent background to the main layout.

I think it how the library works and is not a bug, but i had to say it hehe

Set Behind Content View

First of all, congrats for your great library!
Sorry for my english too...
I'm new with Android, and maybe this question is very easy to resolve.
In setBehindContentView I put with xml layout that declares a fragment in it:

super.onCreate(savedInstanceState);
LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.list_vibing, null);
super.setContentView(v);
mSlidingMenu = (SlidingMenu) super.findViewById(R.id.slidingmenulayout);
setBehindContentView(R.layout.slidingmenumainlist);

slidingmenumainlist.xml :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="15dp"
    android:layout_height="match_parent">
    <fragment android:name="com.convertiva.vibetr.fragments.MenuFragment"
            android:id="@+id/menuList"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent" />
</LinearLayout>

The problem is that the behind ListView layout appears, better example as image:
Alt text

------------------- Next image:

Alt text

Is there any tecnique to hide the behindContent?
Thank you!

Transparent Background with Sherlock

If you change the list size down to not filling the view, the background is transparent using ABS. For example, in SampleListFragment

public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        SampleAdapter adapter = new SampleAdapter(getActivity());
        for (int i = 0; i < 4; i++) {
            adapter.add(new SampleItem(new Fragment(), "Sample List", android.R.drawable.btn_star));
        }
        setListAdapter(adapter);
    }

Starting clean with @iPaulPro ABS example it's also transparent.
I've set a solid background in both the above and behind layout and it still appears transparent after the list.

Anyone else find a way to fix this.
BTW, this is only appearing on my 2.3.3 test device and not on 4.1.1 with the same code.

Ability to show an arrow on the right side of menu.

I wanted the ability to show an arrow on the right side of the menu to indicate the current page. The arrow would float above the drop shadow and animate when the menu was opening and closing.

Screenshot at http://imgur.com/uSjy1

I really need to spend some time learning git instead of copying code in an issue :)

To the code needed in the app to set the location of the arrow:

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    TextView txtOrderCalc = (TextView) findViewById(R.id.txtOrderCalculator);
    computeSelectorTop(txtOrderCalc);
}

/**
 * This sets up the arrow next to this activity on the sliding menu, and
 * will vertically center it to the view.
 * This cannot be called from onCreate, because the screen position for the 
 * View hasn't been calculated yet. 
 * @param view The view to vertically center the selector beside.
 */
private void computeSelectorTop(View view) {
    // Get the offset due to the notification bar
    Rect rectgle= new Rect();
    Window window= getWindow();
    window.getDecorView().getWindowVisibleDisplayFrame(rectgle);
    int statusBarHeight = rectgle.top;
    int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
    int titleBarHeight = contentViewTop - statusBarHeight;

    // Get the top coordinate of the view
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int topView = location[1];

    // Get the selector
    Bitmap selector = BitmapFactory.decodeResource(getResources(), R.drawable.selector);

    // This is the top of the View taking the status bar into account
    int y = topView - titleBarHeight;
    // This will vertically center the selector to the View 
    y = y + ((view.getHeight() / 2) - (selector.getHeight() / 2));

    getSlidingMenu().setSelectorTop(y);
}

Additions to SlidingMenu.java

public void setSelectorDrawable(int resId) {
    mViewAbove.setSelectorDrawable(resId);
}

public void setSelectorTop(int top) {
    mViewAbove.setSelectorTop(top);
}

Changes to CustomViewAbove.java

    private Bitmap mSelectorDrawable;
    private int mSelectorTop;

    public void setSelectorDrawable(int resId) {
        if (resId > 0) {
            mSelectorDrawable = BitmapFactory.decodeResource(getResources(), resId);
            if (mSelectorDrawable != null) 
                refreshDrawableState();
        } else {
            mSelectorDrawable = null;
        }

        invalidate();
    }

    public void setSelectorTop(int top) {
        mSelectorTop = top;

        invalidate();
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        final int behindWidth = this.getBehindWidth();

        // Draw the margin drawable if needed.
        if (mShadowWidth > 0 && mShadowDrawable != null) {
            final int left = behindWidth - mShadowWidth;
            mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
                    mBottomPageBounds);
            mShadowDrawable.draw(canvas);
        }

        float openPercent;
        if (mScrollState == SCROLL_STATE_DRAGGING) {
            openPercent= (behindWidth - Math.min(mLastMotionX, behindWidth)) / (float) behindWidth;
        } else {
            openPercent= (mScroller.getCurrX()) / (float) behindWidth;
        }

        onDrawMenuFade(canvas, openPercent, behindWidth);

        onDrawMenuSelector(canvas, openPercent);
    }

    private Paint mBehindSelectorPaint = new Paint();

    private void onDrawMenuSelector(Canvas canvas, float openPercent) {
        if (mSelectorDrawable != null) {
            // Get the fully opened left position
            int left = this.getBehindWidth() - mSelectorDrawable.getWidth() + 1;
            // Hide/Show selector as the behind view is opened/closed
            left = left + (int)(mSelectorDrawable.getWidth() * openPercent);

            canvas.drawBitmap(mSelectorDrawable, left, mSelectorTop, mBehindSelectorPaint);
        }
    }

Crash in ExampleActivity

On Xoom with JellyBean 4.1.1

It appears that the activePointerIndex on line 1239 of CustromViewAbove class is invalid.

To reproduce, slide the menu open, then start to close it with a drag (press and drag left).
Stop dragging and continue to hold it. Press the content on the right with another finger. Let go, this seems to lock the content in place (menu remains open).
Swipe the content on the right a few times left and right and the crash below occurs consistently.

07-25 18:13:17.330: E/InputEventReceiver(6453): Exception dispatching input event.
07-25 18:13:17.330: E/MessageQueue-JNI(6453): Exception in MessageQueue callback: handleReceiveCallback
07-25 18:13:17.330: E/MessageQueue-JNI(6453): java.lang.IllegalArgumentException: pointerIndex out of range
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.MotionEvent.nativeGetAxisValue(Native Method)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.MotionEvent.getX(MotionEvent.java:1981)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:86)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:210)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.slidingmenu.lib.CustomViewAbove.onTouchEvent(CustomViewAbove.java:1239)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.View.dispatchTouchEvent(View.java:7127)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.View.dispatchPointerEvent(View.java:7307)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.os.MessageQueue.nativePollOnce(Native Method)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.os.MessageQueue.next(MessageQueue.java:125)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.os.Looper.loop(Looper.java:124)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 18:13:17.330: E/MessageQueue-JNI(6453): at dalvik.system.NativeStart.main(Native Method)

Possible to not fork and customize ActionBarSherlock?

Would it be possible to provide full Window (including ActionBar) sliding without forking and changing ActionBarSherlock? This would make integration with existing projects much easier, and will make SlidingMenu significantly easier to maintain. Currently it points to ABS 4.0.1, which doesn't support Android Jelly Bean. Maintaining SlidingMenu's custom fork of ABS could get tedious.

SlidingListActivity - need android.R.id.list (possible fix included)

In order to prevent the following error I made the following modification to SlidingActivityHelper which seems to work. Not sure if there are better ways to achieve the same result but it solves the problem:

    public void onCreate(Bundle savedInstanceState) {
        // unregister the current content view
        mActivity.getWindow().getDecorView().findViewById(android.R.id.content)
                .setId(View.NO_ID);
        // register a new content view

        mContentView = new RelativeLayout(mActivity);
        mContentView.setId(android.R.id.content);

        if (mActivity instanceof SlidingListActivity) {
            ListView lv = new ListView(mActivity);
            lv.setId(android.R.id.list);
            mContentView.addView(lv);
        }

        // set up the SlidingMenu
        mSlidingMenu = (SlidingMenu) LayoutInflater.from(mActivity).inflate(
                R.layout.slidingmenumain, null);
        mSlidingMenu.setViewAbove(mContentView);
        mSlidingMenu.setBackgroundDrawable(mActivity.getWindow().getDecorView()
                .getBackground());
        mActivity.getWindow().setContentView(mSlidingMenu);
    }

SlidingMenu from BOTH left AND right side

Add the ability to add a third view which will display when slid out from the right side. Literally the same functionality that currently exists, but mirrored on the opposite side of the screen

Allow menu to fade in/out as it opens/closes

Here is a code snippet to allow the behind view to fade in/out as it is opening/closing.

Place this in CustomViewAbove.java (overwrite the existing onDraw)

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        final int behindWidth = this.getBehindWidth();

        // Draw the margin drawable if needed.
        if (mShadowWidth > 0 && mShadowDrawable != null) {
            final int left = behindWidth - mShadowWidth;
            mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
                    mBottomPageBounds);
            mShadowDrawable.draw(canvas);
        }

        final float openPercent = (mScroller.getCurrX()) / (float) behindWidth;

        onDrawMenuFade(canvas, openPercent, behindWidth);
    }

    private static final int MAXIMUM_MENU_FADE = 170;
    private Paint mBehindFadePaint = new Paint();

    private void onDrawMenuFade(Canvas canvas, float openPercent, int width) {
        final int alpha = (int) (MAXIMUM_MENU_FADE * openPercent);

        if (alpha > 0) {
            mBehindFadePaint.setColor(Color.argb(alpha, 0, 0, 0));
            canvas.drawRect(0, 0, width, getHeight(), mBehindFadePaint);
        }
    }

Custom opening animations

I cannot seem to find a way to add the "Enhancement" label, but that is all this is.

The Deal In app for iOS has an amazing folding animation. It would be amazing to see SlidingMenu support custom animations the same way Android launchers do. Folding, transparency, rotating cubes, etc. I wouldn't expect most animations to come out-of-the-box but perhaps allow for extensions or something, like dynamically setting the animation at runtime.

Just a though anyway, not sure what other people think. I'd love to help out any way I could with this.

WebView crashes

Hi :)

Just want to report something.

       I found that WebView with SlidingMenu will crash when GPU rendering is enabled.

And it seems ok when GPU rendering is disabled. I tried it on several Jelly Bean and ICS devices.
SlidingMenu works perfect on ICS but not JellyBean. I think crashes will only occur on JB OS.
Except that, everything works great. Thanks for the library! (Sorry for my bad English)

Problem with SherlockMapActivity in SlidingMapActivity

I have just added the last version in Eclipse and I get the following error in the SlidingMapActivity:

The type com.google.android.maps.MapActivity cannot be resolved. It is indirectly referenced from required .class files

Whay should I do to fix it?

Adding MapActivity

Hi!

First of all, congrats for this project! It helps me a lot and the most important thing: very easy!

But now I have a little bit problem. I'm working with activities. When the users click a menu item, new activity starts. But now I'd like to add a MapActivity, do you know how can I do?

Thanks! I'm waiting for your response

No working on android 2.3.3

I am trying to run the app on my defy with android 2.3.3 and I keep getting this exception:

08-09 12:06:40.882: E/AndroidRuntime(12097): FATAL EXCEPTION: main
08-09 12:06:40.882: E/AndroidRuntime(12097): java.lang.NoClassDefFoundError: com.slidingmenu.example.ExampleActivity$PagerAdapter
08-09 12:06:40.882: E/AndroidRuntime(12097): at com.slidingmenu.example.ExampleActivity.onCreate(ExampleActivity.java:29)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.ActivityThread.access$1500(ActivityThread.java:123)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.os.Looper.loop(Looper.java:130)
08-09 12:06:40.882: E/AndroidRuntime(12097): at android.app.ActivityThread.main(ActivityThread.java:3835)
08-09 12:06:40.882: E/AndroidRuntime(12097): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 12:06:40.882: E/AndroidRuntime(12097): at java.lang.reflect.Method.invoke(Method.java:507)
08-09 12:06:40.882: E/AndroidRuntime(12097): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
08-09 12:06:40.882: E/AndroidRuntime(12097): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
08-09 12:06:40.882: E/AndroidRuntime(12097): at dalvik.system.NativeStart.main(Native Method)

Lib compatible with v4?

Last version of this lib is compatible with lib v13 of Android, but not with v4. So, does it mean that I can't use it for Android 2.2 and 2.3.x?
How can I fix it? I tried to import v4, but I can't delete v13, so I still have some problems with getSupportActionBar()

ft.replace method question.

For example
I have 3 list at sliding menu.

  1. Show list (first button)
  2. Show second list (second button)
  3. Show third list

If I chick sliding menu above view will be changed.
When I chick first button, ft.replace(R.id.test_main, new mShowListFragments); is called.
When I chick second button, ft.replace(R.id.test_main, new mShowSecondListFragments); is called.

This works find. But every time when I click sliding menu button I hava to make new fragments.

So make List mFragments = new ArrayList();
and use like this ft.replace(R.id.test_main, mFragments.get(0));

However if I use List sometimes view is not displaied correctly.

If you want to change fragment at above view, how did you make it?

Build problems

Hi, do we have to use your patched version of ActionBarSherlock? It doesn't work with the upstream sources...

default title bar shows on behindview when using ABS

My behind view has a strip at the top of the screen that appears to be the default system title bar. This is only visible on honeycomb(have yet to test on ICS). I am using this with ABS and I am enabling the sliding actionbar. I don't have a fix for this right now...

No up button. Can I still activate the slide on button press?

I'm having an issue implementing this into my application. I'm using ActionBarSherlock, but I'm using a custom layout inside of the actionbar. I have a three line image (similar to FB app) that I want to use to activate the slide. Any easy way to do this?

SampleListFragment Question

How do I get these strings and icons to display instead of the hard coded "Medium Text" and app icon from the row.xml layout?

This is the only part that's edited in the file. I'm showing two list items but not what I'm expecting.

public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
SampleAdapter adapter = new SampleAdapter(getActivity());
//for (int i = 0; i < 20; i++) {
adapter.add(new SampleItem(new Fragment(), "Sample List", android.R.drawable.btn_star));
adapter.add(new SampleItem(new Fragment(), "Sample List 2", android.R.drawable.btn_plus));
//}
setListAdapter(adapter);
}

setup slidingMenu without sherlock

Hi!

Thanks for the great job!

But I have to say that I don't really understand how I am supposed to use it...
I don't need the action bar... don't need sherlock either.
it is written that you can add it to your xml directly so that you can layout as you want but...
how do you do so?

how to change the right part dynamically

This project is great, and the example shows how to extend the sliding activity.
But I am still confused about how to start another normal activity so that it would appear in the right part. For example, the left menu lists "activity1,activity2,activity3“, when the users click on the menu list, the activity
starts accordingly and the menu becomes invisible at the same time.

Unable to get ActionBar to display

I'm trying to create a very basic implementation of your SlidingMenu but am having problems getting the ActionBar to display. When I run my app the sliding mechanic works fine as I can manually slide back and forth but unfortunately I'm not able to get the ActionBar to display.

here's my main activity....

public class MainActivity extends SlidingActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    requestWindowFeature(Window.FEATURE_ACTION_BAR);

    ActionBar actionBar = getSupportActionBar();

    SlidingMenu menu = (SlidingMenu)findViewById(R.id.slidingmenulayout);

    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();   

    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setIcon(R.drawable.sblogo);
    actionBar.show();
}

Other info:

My project and both libraries are set to API 14
I have android:theme="@style/Theme.Sherlock.Light.DarkActionBar" set in my Manifest's activity section.

If anyone has any ideas what I'm doing wrong or overlooking it would be greatly appreciated. Thanks.

'Disable' the above part when slided

First of all : nice work !

My request :
With a behindOffset > 0, when the behind part is showed, the above part is still visible on the right : nice.
But the above part also receives the touch input events (list, button, ...) :
Is it possible to "disable" the above part and handle only the events to close the above part (drag-to-close, home button, ...) ?

Setting width of menu instead of offset

Hello,

It would be very nice if it was possible to set the width of the menu. On tablets (and landscape), it does not make sense to make the menu fill the entire screen horizontally. If the app is always landscape OR portrait, that could be easily done by measuring the display, but tablet apps often need to be able to rotate.

Thanks :)

On Orientation Change Issue

Hi,

First off thanks for the library, I plan on using it in my app EzImgur - I am stuck on this one issue and was hoping you could maybe point me in the right direction (as far as troubleshooting and fixing).

Long story short - I am using the menu on an activity that does not restart on orientation change (android:configChanges="keyboardHidden|orientation|screenSize"). I am using the sliding menu view component (I am not using any of the custom activity classes) as the root view component in my activities and I am setting the "above" content by setting the view above each activity in the set content view.

As far as the issue:
Normally when I hit the home icon on the action bar, it will open the viewBehind and hide the action bar. This all works fine until the screen orientation changes. When the menu is not open and the screen orientation changes - the menu content is magically visible. When I check the sliding menu object to see if the behind view is visible I get false. If i try to hide the menu it does not work (probably because the menu thinks it is not open).

To sum up:

The behind view is being shown on orientation change (even when it was not open before the screen orientation change), and the sliding menu does not even think it is showing - I am unable to hide the menu unless the user clicks a menu item.

Screenshots:
http://imgur.com/a/MsThb
Pic 1: the app normally before opening menu.
Pic 2: the app after opening menu.
Pic 3: the app after orientation change (the menu was not open when I changed orientation.)

SlidingMenu#setFitsSystemWindows problem

Hello. I have downloaded and opened your application with the your library. But Eclipse shows me following error: "Description Resource Path Location Type
The method setFitsSystemWindows(boolean) is undefined for the type RelativeLayout SlidingMenu.java /com.slidingmenu.lib.SlidingMenuActivity/src/com/slidingmenu/lib line 340 Java Problem".
This method appeared to version 14 API, but your library has target=android-8 in project properties.
What to do in this situation?

Non smooth menu scrolling on Galaxy Nexus

Hi! Thanks for great lib! We're using SlidingMenu to build our complex app. When app runs on Galaxy Nexus (stock Android 4.0.4 ROM) menu scrolls very very slow. On other devices (Samsung Galaxy SII, HTC Sensation, LG Optimus One) and emulators with Android 2.2, 2.3.x, 4.1 menu works good. Only Galaxy Nexus has a menu scrolling problem

Fragment issue?

Is it posible to use Sliding menu in activity that is created from fragment? Check this sample from ACS:

https://github.com/JakeWharton/ActionBarSherlock/blob/master/samples/fragments/src/com/actionbarsherlock/sample/fragments/FragmentLayoutSupport.java

I can't use setBehindView in this Activity so how can I use Slidingmenu?

    /**
* This is a secondary activity, to show what the user has selected
* when the screen is not large enough to show it all in one activity.
*/

    public static class DetailsActivity extends SherlockFragmentActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            setTheme(SampleList.THEME); //Used for theme switching in samples
            super.onCreate(savedInstanceState);

            if (getResources().getConfiguration().orientation
                    == Configuration.ORIENTATION_LANDSCAPE) {
                // If the screen is now in landscape mode, we can show the
                // dialog in-line with the list so we don't need this activity.
                finish();
                return;
            }

            if (savedInstanceState == null) {
                // During initial setup, plug in the details fragment.
                DetailsFragment details = new DetailsFragment();
                details.setArguments(getIntent().getExtras());
                getSupportFragmentManager().beginTransaction().add(
                        android.R.id.content, details).commit();
            }
        }
    }

Strange behaviour with android:windowSoftInputMode

I have a ListView in the SlidingMenu layout and I want to use android:windowSoftInputMode to hide the keyboard when the main activity starts because I have three AutoCompleteTextView and one of them always gains focus.
But, it seems android:windowSoftInputMode interferes with my list, so only first item is well displayed. In spite of this strange behaviour, the list works and when I click on an item, it opens a new activity.
Am I doing something wrong? Is there any other way to hide the keyboard when an activity starts? Is there any workaround to avoid this strange behaviour?

Default value of behindScrollScale

Thanks for your fantastic library!
Into the readme you specify that the default value of behind scroll scale il 0, but it is 0.25f :)

Bye

Basic question about setViewAbove

Thanks for making slidemenu library. ^^

User Schenario
: User click behine view lise --> Above View is changed.

If I see detail about setViewAbove() function.
This method accept only 2 type. int res and View v

However I want to use Activity.
If I use Intent I can make it. But sliding menu is not exist.
Intent intent = new Intent();

Is there any way to change Above View by using Activity?

Thanks for reading.

Crash on ICS

Thanks for your great job~ on Android 2.3~3.0 devices it works like a charm:-)
unfortunately, when I test it on emulator4.03 and Moto Xoom(Android4.0.3), it crashed immediately

here is the logcat information:

07-17 11:13:33.670: E/AndroidRuntime(14276): FATAL EXCEPTION: main
07-17 11:13:33.670: E/AndroidRuntime(14276): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.slidingmenu.example/com.slidingmenu.example.ExampleActivity}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to com.slidingmenu.lib.SlidingMenu
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.os.Looper.loop(Looper.java:137)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-17 11:13:33.670: E/AndroidRuntime(14276): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 11:13:33.670: E/AndroidRuntime(14276): at java.lang.reflect.Method.invoke(Method.java:511)
07-17 11:13:33.670: E/AndroidRuntime(14276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-17 11:13:33.670: E/AndroidRuntime(14276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-17 11:13:33.670: E/AndroidRuntime(14276): at dalvik.system.NativeStart.main(Native Method)
07-17 11:13:33.670: E/AndroidRuntime(14276): Caused by: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to com.slidingmenu.lib.SlidingMenu
07-17 11:13:33.670: E/AndroidRuntime(14276): at com.slidingmenu.lib.app.SlidingActivityHelper.onCreate(SlidingActivityHelper.java:35)
07-17 11:13:33.670: E/AndroidRuntime(14276): at com.slidingmenu.lib.app.SlidingFragmentActivity.onCreate(SlidingFragmentActivity.java:18)
07-17 11:13:33.670: E/AndroidRuntime(14276): at com.slidingmenu.example.ExampleActivity.onCreate(ExampleActivity.java:27)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.Activity.performCreate(Activity.java:4465)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-17 11:13:33.670: E/AndroidRuntime(14276): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-17 11:13:33.670: E/AndroidRuntime(14276): ... 11 more

ArithmeticException

I just noticed this today and thought that I would report it, it seems that there is an issue with the following line:

final int position = xpos / widthWithMargin;

Now I know what I did in this case was call setBehindOffset with a variable width calculated by screen size, set to a maximum of the window's width. On my Motorola Droid X the resolution is 480x800 and I called setBehindOffset with 480 using SlidingMenu.TOUCHMODE_MARGIN.
I've since put the touch mode in a conditional statement, but to spare what might cause issue in the future I would always check for zero before dividing.

java.lang.ArithmeticException: divide by zero
    at com.slidingmenu.lib.CustomViewAbove.pageScrolled(CustomViewAbove.java:929)
    at com.slidingmenu.lib.CustomViewAbove.onTouchEvent(CustomViewAbove.java:1268)
    at android.view.View.dispatchTouchEvent(View.java:3885)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:903)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1919)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1186)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2142)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1903)
    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3806)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)

Trying to toggle onClick

I have a button set onClick to execute "settings" in my xml. I get a crash when I attempt to toggle the sliding menu.

Before my oncreate

SlidingActivity slider;

Then I added a new method.

public void settings(View view) {
        slider.toggle();
    }

But I get an illegal state exception when the button is hit. Am I going about this the wrong way? Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.