1

我正在尝试执行类似 Google/Youtube 应用程序的操作,通过单击
顶部的操作栏将在屏幕左侧填充一个菜单。

除此之外,我还立即使用 Scrollable Tabs + Swipe 导航类型。我在谷歌上做了一些研究,发现了滑动菜单库,但我不知道如何开始将它们整合在一起。


现在我有 Swipe 导航的默认类和扩展 SlidingActivity 的类,如下所示:


公共类 Home 扩展 FragmentActivity {

static int POSITION;
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setDisplayUseLogoEnabled(false);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setDisplayShowHomeEnabled(true);
    setContentView(R.layout.home);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(
            getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.home, menu);

    return true;
}

/**
 * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    public SectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a DummySectionFragment (defined as a static inner class
        // below) with the page number as its lone argument.
        POSITION = position;
        Fragment fragment = new DummySectionFragment();

        Bundle args = new Bundle();
        args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, position + 1);
        fragment.setArguments(args);

        return fragment;
    }

    @Override
    public int getCount() {
        // The number of pages
        return 5;
    }

    String[] Modules = { "IT1111-AV", "IT1431-AV", "IT1161-AX",
            "IT1432-AV", "IT631-AV" };

    @Override
    public CharSequence getPageTitle(int position) {
        Locale l = Locale.getDefault();

        for (int i = 0; i < Modules.length; i++) {
            if (i == position) {
                return Modules[i];
            }

        }

        return null;
    }
}

/**
 * A dummy fragment representing a section of the app, but that simply
 * displays dummy text.
 */
public static class DummySectionFragment extends Fragment {
    /**
     * The fragment argument representing the section number for this
     * fragment.
     */
    public static final String ARG_SECTION_NUMBER = "section_number";



    public DummySectionFragment() {

    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        if (POSITION == 2) {
            View rootView = inflater.inflate(R.layout.fragment_home_dummy,
                    container, false);
            TextView dummyTextView = (TextView) rootView
                    .findViewById(R.id.section_label);
            dummyTextView.setText("YOLO");
            return rootView;
        }
        View rootView = inflater.inflate(R.layout.fragment_home_dummy,
                container, false);
        TextView dummyTextView = (TextView) rootView
                .findViewById(R.id.section_label);
        dummyTextView.setText(Integer.toString(getArguments().getInt(
                ARG_SECTION_NUMBER))
                + "HELLO");
        return rootView;
    }




}

}



滑动活动类:

公共类幻灯片扩展滑动活动{

@Override
public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setBehindContentView(R.layout.activity_menu);

getSlidingMenu().setBehindOffset(100);
}

}


那么这是一种将这两者整合在一起的简单方法吗?我是Android开发的新手,所以请指导我!

4

1 回答 1

0

这是您需要的示例。https://github.com/jfeinstein10/SlidingMenu/

于 2013-04-04T02:34:56.820 回答