如何通过将主页面向右拖动来停止滑动

时间:2013-10-12 10:35:05

标签: android slidingmenu

我已经完成了MenuSlider,但我只是想在动作单击主页按钮时滑动怎么办我不知道要解决这个问题因为我必须添加4个标签然后导航到它们似乎很难

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    StrictMode.enableDefaults();


    Drawable d=getResources().getDrawable(R.drawable.action_bar);  

    actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    //actionBar.setTitle("Action Bar");
    actionBar.setLogo(R.drawable.transparent);
    //actionBar.setSubtitle("http://www.android.com");
    actionBar.addOnMenuVisibilityListener(this);
    actionBar.setBackgroundDrawable(d);


    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(true);
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
    getActionBar().setHomeButtonEnabled(true);
    getOverflowMenu();

    setBehindContentView(R.layout.left_tab);
    setSlidingActionBarEnabled(true);
    slideMenu = getSlidingMenu();
    slideMenu.setMode(SlidingMenu.LEFT);
    slideMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    slideMenu.setShadowWidthRes(R.dimen.slidingmenu_offset);
    //slideMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    slideMenu.setBehindOffset(80);
    slideMenu.setFadeDegree(0.99f);

    inflater = getLayoutInflater();
    //item = inflater.inflate(R.layout.left_tab, null);}
}

1 个答案:

答案 0 :(得分:1)

尝试更改

slideMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);

slideMenu.setTouchModeAbove(SlidingMenu.ABOVE); 
  

touchModeAbove - 一个枚举,用于指定在显示上述视图时可触摸屏幕的哪个部分。保证金仅指左边距。全屏意味着整个屏幕。默认为保证金。

简单示例

public class SlidingExample extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.attach);
    // set the content view
    setContentView(R.layout.content);
    // configure the SlidingMenu
    SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
    menu.setMenu(R.layout.menu);
}

}

XML用法

如果您决定使用SlidingMenu作为视图,您可以在xml布局中定义它,如下所示:

<com.jeremyfeinstein.slidingmenu.lib.SlidingMenu
    xmlns:sliding="http://schemas.android.com/apk/res-auto"
    android:id="@+id/slidingmenulayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"
    sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"
    sliding:touchModeAbove="margin|fullscreen"
    sliding:behindOffset="@dimen/YOUR_OFFSET"
    sliding:behindWidth="@dimen/YOUR_WIDTH"
    sliding:behindScrollScale="@dimen/YOUR_SCALE"
    sliding:shadowDrawable="@drawable/YOUR_SHADOW"
    sliding:shadowWidth="@dimen/YOUR_SHADOW_WIDTH"
    sliding:fadeEnabled="true|false"
    sliding:fadeDegree="float"
    sliding:selectorEnabled="true|false"
    sliding:selectorDrawable="@drawable/YOUR_SELECTOR"/>
  

此类在API级别17中已弃用。此类不再受支持。如果您必须在应用程序中使用它,建议您将自己的实现基于Android开源项目的源代码。

输出:

enter image description here