0

我正在开发一个使用 jfeinstein10/SlidingMenuAction Bar Sherlock的 Android 应用程序。

这是我第一次使用它,我不知道如何在非全屏模式下打开它。我想看看活动和菜单。

这是我的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" />

还有我的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>

我的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>

还有我的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>

对于我onCreate的活动:

@覆盖

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

并且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()
    {
     [ ... ]
    }
}

我想像 Facebook 的应用一样显示菜单。我该怎么做?

4

4 回答 4

1

请参阅我在此处发布的没有 ActionBar 的 SlindingMenu代码,它适用于我作为 Facebook / Foursquare 菜单。这些线路未实施/与您不同:

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

试试看。

于 2013-07-10T08:39:58.967 回答
0

搜索我发现以下内容:

  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>
于 2013-11-17T03:00:52.660 回答
-1

please try this....

 getSlidingMenu().setBehindOffset(100);
于 2013-10-21T13:31:30.320 回答
-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.

于 2013-09-11T15:28:58.200 回答