我正在开发一个使用 jfeinstein10/SlidingMenu和Action 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 的应用一样显示菜单。我该怎么做?