滑动菜单完全隐藏使用jfeinstein10 / SlidingMenu库

时间:2015-02-02 11:17:03

标签: android navigation-drawer amslidemenu

您好我正在使用jfeinstein10 / SlidingMenu库将幻灯片菜单实现到我的项目中。

HomePage.java

    import android.os.Bundle;
    import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
    import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

     public class HomePage extends SlidingFragmentActivity {

    SlidingMenu menu;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_page);
        setBehindContentView(R.layout.behind);

        //customize the slide menu
        menu = new SlidingMenu(this);
        menu.setMode(SlidingMenu.LEFT);
        menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);       
        menu.setShadowWidthRes(R.dimen.shadow);
        menu.setFadeDegree(0.35f);
        menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        menu.setBehindOffsetRes(R.dimen.slidewidth);

    }
    }

XML文件:

activity_home_page.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

behind.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="match_parent"
    android:orientation="vertical" >


</LinearLayout>

dimen.xml

  **<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name = "slidewidth">60dp</dimen>

    <dimen name="shadow">15dp</dimen>
</resources>**

我的问题是,

运行应用程序时,我会滑动屏幕,但屏幕完全隐藏不是代码设置的偏移量

    menu.setBehindOffsetRes(R.dimen.slidewidth);

我做错了什么?有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您已在android:layout_width="match_parent"

中向LinearLayout提供了behind.xml

给它wrap_content

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >

希望它有助于ツ