0

I'm developing an Android application that uses jfeinstein10/SlidingMenu with Action Bar Sherlock.

It is the first time I used it and I don't know how to open it on not full screen mode. I want see the activity and the menu.

This is my menu_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="5dip"
    android:paddingRight="5dip" />

And my menu_row.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/menuIcon"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:padding="10dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/menuTitle"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:padding="10dp"
        android:text=""
        android:textAppearance="@android:style/TextAppearance.Medium" />
</LinearLayout>

And my menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/slidingMenuFragment"
    android:name="com.com.msx.fragments.MenuFragment"
    android:layout_width="2dp"
    android:layout_height="match_parent">
</fragment>

And my dimens.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="slidingmenu_width">5dp</dimen>
    <dimen name="slidingmenu_offset">60dp</dimen>
    <dimen name="list_padding">10dp</dimen>
    <dimen name="shadow_width">15dp</dimen>
    <integer name="num_cols">1</integer>
</resources>

And onCreate for my activity:

@Override

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setBehindContentView(R.layout.menu);

        setSlidingActionBarEnabled(false);        

        slidingMenu = new SlidingMenu(this);
        slidingMenu.setMode(SlidingMenu.LEFT);
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
        slidingMenu.setShadowWidthRes(R.dimen.shadow_width);
        slidingMenu.setShadowDrawable(R.drawable.shadow);
        slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        slidingMenu.setFadeDegree(0.35f);
        slidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

        getSupportActionBar().setDisplayShowCustomEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

And MenuFragment:

public class MenuFragment extends ListFragment
{
    private static final String TAG = "MenuFragment";
    /**
     * Menu items to show in this Sliding Menu. 
     */
    private ArrayList<MenuItem> mMenuItems;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState)
    {
        return inflater.inflate(R.layout.menu_list, null);
    }

    public void onActivityCreated(Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);

        // Get menu items.
         mMenuItems = getMenuItems();

        MenuAdapter adapter = new MenuAdapter(getActivity(),
                R.layout.menu_row, mMenuItems);
        setListAdapter(adapter);
    }

    /**
     * Get menu items to show on Sliding menu.
     * @return
     */
    private ArrayList<MenuItem> getMenuItems()
    {
     [ ... ]
    }
}

I want to show the menu like Facebook's app does. How can I do it?

VansFannel
  • 45,055
  • 107
  • 359
  • 626

4 Answers4

1

See the code I posted here SlindingMenu without ActionBar, It works for me as the Facebook / Foursquare menu. Those Lines are not implemented / different from your side :

menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

Try it.

Community
  • 1
  • 1
marshallino16
  • 2,645
  • 15
  • 29
  • Thanks for your answer. I've changed it on my code and I get the same: it opens full screen. Btw, I'm testing it on Android Emulator. And on a HTC DEsire with Android 2.2.2, it gets full screen. – VansFannel Jul 10 '13 at 10:12
  • Try to fix the width of menu layout to x dp, just for testing – marshallino16 Jul 10 '13 at 10:19
  • I have updated my question with some changes on `dimens.xml` and `menu.xml`and changes that you have suggested me. I'm using it with Action Bar Sherlock and ActionBar doesn't move like this one: http://i.stack.imgur.com/QwlYm.png – VansFannel Jul 10 '13 at 10:28
  • This will not work if you have a set of tabs and you want the sliding menu to appear on full screen. – Paulo Almeida Jan 21 '14 at 06:33
0

Searching I found the following:

  SlidingMenu sm = getSlidingMenu();
  sm.setShadowWidthRes(R.dimen.slidingmenuWidth);
  sm.setBehindOffsetRes(R.dimen.slidingmenuOffset);
  sm.setFadeDegree(0.35f);
  sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

  <dimen name="slidingmenuWidth">15dp</dimen>
  <dimen name="slidingmenuOffset">60dp</dimen>
-1

I don't know if you still need this answer but I had the same problem using the same slidingmenu than you and I fixed it changing the dimension of this parameter:

lateralMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);

If you set to 0dp, the slidingmenu will be opened full-screen. For my app, I needed two differents dimensions of the sliding menu if I was using tablets or hand devices. I setted different dimensions for this parameter using different dimen.xml files.

Hope to be helpfull.

Juan Pedro Martinez
  • 1,924
  • 1
  • 15
  • 24
-1

please try this....

 getSlidingMenu().setBehindOffset(100);
Lalit Sharma
  • 1,142
  • 1
  • 15
  • 32