这个问题在这里已有答案:

Introduction
我正在创建一个Android应用程序 . 它包含一个导航抽屉 .

My Problem
在我的应用程序中,我使用onclick事件启用相对布局的可见性 . 在onclick事件之后,相对布局变得可见 .

现在问题是,在启用相对布局“导航抽屉”的可见性之前,工作完美 .

但是在视图可见后,当我点击抽屉上的任何菜单项时,导航抽屉开始缩回 . 但在启用视图之前,导航抽屉菜单项会完美响应

我无法弄清楚问题所在 . 我使用了 mDrawerLayout.bringToFront(); mDrawerLayout.requestLayout(); 但没有实现解决方案

My Code:

Map_Activity.xml

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true">


<RelativeLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/myCoordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


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

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:map="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.cog.shyperDriver.Map_Activity">

        </fragment>

        <RelativeLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:background="@color/colorPrimary">

            <RelativeLayout
                android:id="@+id/onlinelay"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentBottom="true"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="10dp"
                android:layout_marginStart="150dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/custom_alert_corner"
                android:onClick="clickOnline"
                android:visibility="visible">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="7dp"
                    android:layout_toLeftOf="@+id/onlineTxt"
                    android:background="@drawable/lock_outline" />

                <TextView
                    android:id="@+id/onlineTxt"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:text="@string/go_online"
                    android:textColor="@color/appColor"
                    android:textSize="15sp" />

            </RelativeLayout>

            <TextView
                android:id="@+id/onlineTxt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:fontFamily="@string/app_font_regular"
                android:text="Home"
                android:textColor="@color/colorPrimary"
                android:textSize="20sp"
                android:textStyle="bold"
                android:visibility="gone" />

            <ImageView
                android:id="@+id/btmenu"
                android:layout_width="30dp"
                android:layout_height="30dp"
                 android:layout_alignParentTop="true"
                android:layout_marginTop="10dp"
                android:padding="10dp"
                android:layout_marginStart="10dp"
                android:background="@drawable/ic_menu"
                android:elevation="5dp" />


        </RelativeLayout>

        <!--</fragment>-->




    <!--current location -->
    <RelativeLayout
        android:id="@+id/myLocationButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_gravity="top|end"
        android:layout_marginRight="20dp"
        android:layout_marginTop="200dp"
         android:background="@drawable/circle">

        <ImageView
            android:id="@+id/myLocationImg"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:src="@drawable/gpsloc" />
    </RelativeLayout>

    <!--bottom bar-->
    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_gravity="bottom"
        android:visibility="gone"
        app:bb_tabXmlResource="@xml/bottombars_tabs_three" />




</RelativeLayout>

<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="com.cog.shyperDriver.adapter.FragmentDrawer"
android:layout_width="140dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navi_drawer"
tools:layout="@layout/fragment_navi_drawer" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="gone"
    android:id="@+id/offlineLayout"
    android:background="#fff">


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

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:padding="10dp"
            android:src="@drawable/ic_menu"
            android:contentDescription="@string/todo"
            android:id="@+id/dialogMenu"/>

    </RelativeLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/footer"
        android:layout_below="@+id/header">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerInParent="true"
                android:layout_centerVertical="true"
                android:layout_margin="20dp"
                android:orientation="vertical"
                tools:ignore="UselessParent">

                <ImageView
                    android:layout_width="200dp"
                    android:layout_height="200dp"
                    android:layout_gravity="center_horizontal"
                    android:src="@drawable/online_logo"
                    android:contentDescription="@string/todo" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="0dp"
                    android:fontFamily="@string/app_font_medium"
                    android:gravity="center_horizontal"
                    android:text="@string/you_are_offline"
                    android:textColor="@color/colorPrimary"
                    android:textSize="18sp"
                    android:id="@+id/onoffstatus"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="0dp"
                    android:fontFamily="@string/app_font_medium"
                    android:gravity="center_horizontal"
                    android:text="@string/you_seems_to_be_offline"
                    android:textColor="@color/textcolor"
                    android:textSize="18sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="0dp"
                    android:fontFamily="@string/app_font_medium"
                    android:gravity="center_horizontal"

android:text="@string/go_online_to_start_earning_right_away"
                    android:textColor="@color/textcolor"
                    android:textSize="18sp" />


            </LinearLayout>


        </RelativeLayout>
        <!--app:kswBackDrawable="@drawable/switch_bg"
        app:kswThumbDrawable="@drawable/switch_background_white"-->
    </ScrollView>

    <RelativeLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10sp"
            android:padding="10dp"
            android:src="@drawable/ic_menu"
            android:visibility="invisible"
            android:contentDescription="@string/todo" />


    </RelativeLayout>

</RelativeLayout>

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

在上面的代码中,ID为offlineLayout的布局在启用visibilty后创建了上述问题 .

启用布局可见性的代码:

public void showOfflineDialog(boolean isOffline) {

RelativeLayout offlineLayout = (RelativeLayout) findViewById(R.id.offlineLayout);

if (isOffline)
{
    offlineLayout.setVisibility(View.VISIBLE);
    mDrawerLayout.bringToFront();
    mDrawerLayout.requestLayout();
}
else
{
    mDrawerLayout.bringToFront();
    mDrawerLayout.requestLayout();
    offlineLayout.setVisibility(View.GONE);
}


}

启用offlinelayout后,导航抽屉不响应点击次数..简单地回退 .

CodeBlock the initialise Navigation Drawer::

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    drawerFragment = (FragmentDrawer)
          getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
    drawerFragment.setDrawerListener(this);

方法处理Nav Drawer中项目的OnClick事件

@Override
    public void onDrawerItemSelected(View view, int position) {


        switch (position) {
            case 0:
                Intent intent = new Intent(Map_Activity.this, YourTripsActivity_.class);
                startActivity(intent);
                break;
            case 1:
                Intent earnings = new Intent(Map_Activity.this, EarningActivity_.class);
                startActivity(earnings);
                break;
            case 2:
                Intent summary = new Intent(Map_Activity.this, EarningActivity_.class);
                startActivity(summary);
                break;
            case 3:
                Intent help = new Intent(Map_Activity.this, Help_activity.class);
                startActivity(help);
                break;

            case 4:
                logout();
                break;

            default:
                break;
        }


    }

上面的代码在显示offlineLayout之前完全响应,但在显示offlineLayout后无法正常工作

Final Request
我努力解决这个问题,但我找不到任何解决方案 . 请帮我 .