我正在使用 jfeinstein10 的 SlidingMenu 和 ActionBarSherlock。当我向右滑动时,滑动菜单完美显示(仅以特定宽度显示)。但是当我点击一个按钮(SLIDEMENU)来显示滑动菜单(使用切换())时,它会显示整个菜单(覆盖整个屏幕)。如何在不覆盖整个屏幕的情况下显示滑动菜单?这是我的活动和菜单 xml..
主要活动:
public class MainActivity extends SlidingFragmentActivity{
private static final int SLIDEMENU = 1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setBehindContentView(R.layout.sliding_menu);
getSupportActionBar().setIcon(android.R.color.transparent);
SlidingMenu menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
menu.setMenu(R.layout.sliding_menu);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
menu.setBehindWidth((displaymetrics.widthPixels)/2);
}
@Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
menu.add(0,SLIDEMENU,0,"Menu")
.setIcon(R.drawable.btnmenu)
.setShowAsAction(com.actionbarsherlock.view.MenuItem.SHOW_AS_ACTION_ALWAYS);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == SLIDEMENU) {
toggle();
}
return super.onOptionsItemSelected(item);
}
}
滑动菜单.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="@dimen/menuWidth"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@android:color/transparent" >
<TextView android:id="@+id/test1"
android:layout_width="@dimen/menuWidth"
android:layout_height="wrap_content"
android:textSize="@dimen/font_size"
android:text="@string/test1" />
<TextView
android:id="@+id/test2"
android:layout_width="@dimen/menuWidth"
android:layout_height="wrap_content"
android:layout_below="@+id/test1"
android:layout_marginTop="15dp"
android:textSize="@dimen/font_size"
android:text="@string/test2" />
<TextView
android:id="@+id/test3"
android:layout_width="@dimen/menuWidth"
android:layout_height="wrap_content"
android:layout_below="@+id/test2"
android:layout_marginTop="15dp"
android:textSize="@dimen/font_size"
android:text="@string/test3" />