Question

I am having issue where my sliding menu for what ever reason takes up the full screen... I have looked around and had people saying you need to set setBehindOffsetRes or setBehindOffset to get it to work.. I have but it still doesn't work..

Main Activity:

package com.quapps.theinitiative;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.quapps.theinitiative.R;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends SlidingFragmentActivity {

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

        setBehindContentView(R.layout.menu_frame);

        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_frame);
        //menu.setBehindOffset(100);


    }
}

dimens.xml

<resources>

    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>

    <dimen name="slidingmenu_offset">60dp</dimen>
    <dimen name="list_padding">10dp</dimen>
    <dimen name="shadow_width">15dp</dimen>

</resources>

menu_frame.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/menu_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

activity_main

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

I understand it's probably something stupid, I just can't seem to find it

Was it helpful?

Solution

Setting the width of SlidingMenu should do the trick, here's how you can do it in code.

getSlidingMenu().setBehindWidthRes(300dp);

300dp should be specified in resource/dimen file so at run-time it can be converted to pixel value accordingly. If you want to specify pixels directly you can use '300' only.

OTHER TIPS

In menu_frame.xml change android:layout_width="match_parent" to android:layout_width="wrap_content" should work

in menu.xml file add width to wrapcontent

Specify the width in resource/dimen file like 100dp do work. You can't write getSlidingMenu().setBehindWidthRes(300), or it will give resource not found error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top