Strange offset behavior on slidingmenu

江枫思渺然 提交于 2019-12-22 01:16:59

问题


i´m trying to include the SlidingMenu to my application. It combines the 3 libraries ActionBarSherlock / ViewPagerIndicator / SlidingMenu. Well the problem is if i´m sliding to the right to expand the SlidingMenu it has no Offset. That means the hole screen will be filled by the menu. If i´m pressing the toggle button it looks really strange. It seems that he got the offset but look on the picture... If i´m pressing the toggle button twice it looks like it should -.-'

Any idea what i have done wrong?

Thats my layout.xml

<LinearLayout 
android:id="@+id/id_Main_output"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1.0"
android:orientation="vertical" >

<com.viewpagerindicator.TitlePageIndicator
    android:id="@+id/id_Main_titlepageindicator"
    android:textColor="#FF808080"
    app:selectedColor="#FF33B5E5"
    app:selectedBold="true"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    />
<android.support.v4.view.ViewPager
    android:id="@+id/id_Main_pager"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />

</LinearLayout>

And this is my onCreate

super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_mensaplanhsulm);
    setBehindContentView(R.layout.layout_settings);

    mPager              = (ViewPager)findViewById(R.id.id_Main_pager);
    mIndicator          = (TitlePageIndicator)findViewById(R.id.id_Main_titlepageindicator);
    mAdapter = new DayTitleFragmentAdapter(getSupportFragmentManager());
    mPager.setAdapter(mAdapter);
    mPager.setCurrentItem(0);
    mIndicator.setViewPager(mPager);

    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.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    menu.setAboveOffset(R.dimen.slidingmenu_offset);
    menu.setFadeDegree(0.35f);
    menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
    menu.setMenu(R.layout.layout_settings);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    setSlidingActionBarEnabled(true);

回答1:


That´s what I use:

// customize the SlidingMenu
        setBehindContentView(R.layout.menu_frame);
        FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
        mFrag = new SlidingFragment();
        t.replace(R.id.menu_frame, mFrag);
        t.commit();

                SlidingMenu sm = getSlidingMenu();
                sm.setShadowWidthRes(R.dimen.shadow_width);
                sm.setShadowDrawable(R.drawable.shadow);
                sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
                sm.setFadeDegree(0.35f);
                setSlidingActionBarEnabled(true);

                getSupportActionBar().setDisplayHomeAsUpEnabled(true);

dimen.xml

<resources>

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

    <integer name="num_cols">1</integer>

</resources>

Sample:

https://www.4shared.com/rar/zOWrvmyu/ViewpagerandSherlock.html

This sample is perfectly working viewpager and sherlock.

Just implement this code in BaseSampleActivity extends SlidingFragmentActivity, create a simple SlidingFragment and it will works.

You need to extend a SlidingMenu class. To also use the ActionBar Sherlock library you must follow the steps listed in the Readme, in particular this one:

Go into the SlidingActivities that you plan on using make them extend Sherlock__Activity instead of __Activity.

So your project should extend SlidingActivity:

public class Waiter extends SlidingActivity {

And you need to change your copy of the SlidingMenu library to use ABS. Open com/slidingmenu/lib/app/SlidingActivity.java and change:

public class SlidingActivity extends Activity implements SlidingActivityBase {

to:

public class SlidingActivity extends SherlockActivity implements SlidingActivityBase {
//             Add "Sherlock" here:  ^^^^^^^^

(Repeat this step for any other SlidingMenu Activities you wish to use.)




回答2:


This answer isn´t necessary so I edited to focus other one!



来源:https://stackoverflow.com/questions/14711892/strange-offset-behavior-on-slidingmenu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!