1

我正在使用 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" />

4

2 回答 2

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-17T02:56:33.303 回答
0

您可以设置behindWidth

    menu.setBehindWidth(your-value-here);
于 2013-09-06T03:20:00.207 回答