【问题标题】:How can I implement an Android navigation drawer which slide whole content of activity?如何实现一个滑动整个活动内容的 Android 导航抽屉?
【发布时间】:2017-02-16 03:09:43
【问题描述】:

请任何人建议我如何实现导航抽屉滑动完整屏幕的活动。

提前致谢。

***---------

解决方案

--------*:** 我找到了解决方案。

使用这个库很容易使用和处理

https://github.com/adamrocker/simple-side-drawer

【问题讨论】:

标签: android android-activity android-actionbar navigation-drawer


【解决方案1】:

您可以尝试将此布局用于抽屉活动。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp"
    >

    <RelativeLayout
        android:id="@+id/content_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/drawer_holder"
        android:layout_width="@dimen/drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        >

        <ListView
            android:id="@+id/drawer_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    </FrameLayout>

</android.support.v4.widget.DrawerLayout>

然后像这样将DrawerLayout.DrawerListener 添加到DrawerLayout

drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
            @Override
            public void onDrawerSlide(View view, float slideOffset) {
                drawerView.setX(drawerHolder.getWidth() * (1 - slideOffset));
                contentLayout.setX(drawerHolder.getWidth() * slideOffset);
            }

            @Override
            public void onDrawerOpened(View view) {
            }

            @Override
            public void onDrawerClosed(View view) {
            }

            @Override
            public void onDrawerStateChanged(int newState) {
            }
        });

在添加listner 之后放入这段代码。

drawerLayout.closeDrawer(drawerHolder);
mainDrawerView.setX(0);
contentLayout.setX(0);

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 2015-02-24
    相关资源
    最近更新 更多