ARB
ARB

Reputation: 53

JFEinstien sliding menu unable to set width of the behind view

I was working on implementing the sliding menu.

I want to set the width of the sliding menu as 2/3 of the screen width when active.

Here is my MainActivity

public class MainActivity extends SlidingActivity {

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

    getSupportActionBar().setHomeButtonEnabled(true);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    setBehindContentView(R.layout.slidemenu_layout);

    setSlidingActionBarEnabled(false);

    SlidingMenu menu = new SlidingMenu(this);
    menu.setMode(SlidingMenu.LEFT);
    menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
    menu.setShadowWidthRes(R.dimen.shadow_width);
    menu.setShadowDrawable(R.drawable.shadow);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);

    menu.setBehindWidth((2*displaymetrics.widthPixels)/3);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getSupportMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        toggle();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

*NOTE :*I had initially made MainActivity extend Activity and it was working fine there. I had to move to SlidingActivity to implement Action Bar Sherlock

EDIT :I replaced SlidingActivity with SherlockActivity and deleted the setBehindContentView(..) and carried on.But no clue why 1st one did not work.

Upvotes: 2

Views: 2871

Answers (2)

ingh.am
ingh.am

Reputation: 26772

Have you tried using setBehindWidthRes rather than setBehindOffsetRes?

Upvotes: 3

Axarydax
Axarydax

Reputation: 16603

You can try setting the behind width with setBehindOffsetRes, and passing an id from a resource XML, like in this answer.

Upvotes: 0

Related Questions