如何使用Simon VTs SlidingMenu?

时间:2013-05-28 05:02:02

标签: android

所以,这是我的第一个问题。我已经花了好几个小时寻找答案/解决方案而没有人“牵着我的手”,但坦率地说。我还不擅长Java。 (我是超级新人,自己自学)。

问题:如何创建可以在滑动菜单中单击的片段(向左滑动时),然后让它打开一个打开文本视图的列表视图?

即。 您可以滑动打开菜单,单击一个选项,抽屉关闭并转到选项列表视图,每次单击每个列表视图项都会打开不同的文本视图。

这是我的MainActivity代码:

public class MainActivity extends SherlockActivity {

    private static final String STATE_MENUDRAWER = "net.simonvt.menudrawer.samples.WindowSample.menuDrawer";
    private static final String STATE_ACTIVE_VIEW_ID = "net.simonvt.menudrawer.samples.WindowSample.activeViewId";

    private MenuDrawer mMenuDrawer;
    private TextView mContentTextView;

    private int mActiveViewId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        if (savedInstanceState != null) {
            mActiveViewId = savedInstanceState.getInt(STATE_ACTIVE_VIEW_ID);
        }

        mMenuDrawer = MenuDrawer.attach(this, MenuDrawer.MENU_DRAG_WINDOW);
        // mMenuDrawer.setContentView(R.layout.activity_windowsample);
        mMenuDrawer.setMenuView(R.layout.menu_layout);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }

    @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 true;
    }

    @Override
    protected void onRestoreInstanceState(Bundle inState) {
        super.onRestoreInstanceState(inState);
        mMenuDrawer.restoreState(inState.getParcelable(STATE_MENUDRAWER));
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putParcelable(STATE_MENUDRAWER, mMenuDrawer.saveState());
        outState.putInt(STATE_ACTIVE_VIEW_ID, mActiveViewId);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            mMenuDrawer.toggleMenu();
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        final int drawerState = mMenuDrawer.getDrawerState();
        if (drawerState == MenuDrawer.STATE_OPEN
                || drawerState == MenuDrawer.STATE_OPENING) {
            mMenuDrawer.closeMenu();
            return;
        }

        super.onBackPressed();
    }
}

这是我的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:layout_alignBottom="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="29dp"
        android:text="@string/welcome" 
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/slide"
        android:textAppearance="?android:attr/textAppearanceMedium" />

这是我的menu_layout:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/item1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_refresh_dark"
            android:text="@string/about"
            style="@style/MenuDrawer.Widget.Title" />

        <TextView
            android:id="@+id/item2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_select_all_dark"
            android:text="@string/help"
            style="@style/MenuDrawer.Widget.Title" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/definitions"
            style="@style/MenuDrawer.Widget.Category" />

        <TextView
            android:id="@+id/item3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_refresh_dark"
            android:text="@string/cpu_governors"
            style="@style/MenuDrawer.Widget.Title" />

        <TextView
            android:id="@+id/item4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_select_all_dark"
            android:text="@string/io_schedulers"
            style="@style/MenuDrawer.Widget.Title" />

        <TextView
            android:id="@+id/item5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_refresh_dark"
            android:text="@string/tcp_algorithms"
            style="@style/MenuDrawer.Widget.Title" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/options"
            style="@style/MenuDrawer.Widget.Category" />

        <TextView
            android:id="@+id/item6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_select_all_dark"
            android:text="@string/settings"
            style="@style/MenuDrawer.Widget.Title" />

                <TextView
            android:id="@+id/item7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableLeft="@drawable/ic_action_select_all_dark"
            android:text="@string/theme"
            style="@style/MenuDrawer.Widget.Title" />

    </LinearLayout>
</ScrollView>

这是我的字符串:

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

    <string name="app_name">MBQs CPU Guide</string>
    <string name="action_settings">Settings</string>
    <string name="welcome">Welcome to my CPU Guide! :)</string>
    <string name="slide">Slide left to view your options!</string>
    <string name="about">About</string>
    <string name="help">Help</string>
    <string name="definitions">Definitions</string>
    <string name="cpu_governors">CPU Governors</string>
    <string name="io_schedulers">IO Schedulers</string>
    <string name="tcp_algorithms">TCP Algorithms</string>
    <string name="options">Options</string>
    <string name="settings">Settings</string>
    <string name="theme">Theme</string>

</resources>
提前谢谢。 :)希望我在问一个问题时做的一切都很正确,如果我不这样做,我会道歉。

1 个答案:

答案 0 :(得分:0)

只需转到该链接并下载压缩文件here

即可

有2个库和一个项目文件。

从项目文件中删除所有不需要的代码和类,并使用必要的类......