gpt4 book ai didi

android - NavigationDrawer isDrawerOpened 总是返回 true

转载 作者:行者123 更新时间:2023-11-30 01:53:54 25 4
gpt4 key购买 nike

我遇到了奇怪的问题。我在我的应用程序中使用支持库中的抽屉导航。
这是布局

   <android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_layout_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:visibility="gone" />
</LinearLayout>

<ScrollView
android:id="@+id/layout_drawer_left"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fillViewport="true">

</ScrollView>

<ScrollView
android:id="@+id/layout_drawer_right"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:fillViewport="true" />
</android.support.v4.widget.DrawerLayout>

我在设置内容 View 后找到所有 View 。

private FrameLayout mLeftDrawerContainer, mRightDrawerContainer;
private DrawerLayout mDrawerMainLayout;
mDrawerMainLayout = (DrawerLayout) rootBaseView.findViewById(R.id.navigation_drawer);
mLeftDrawerContainer = (ScrollView) rootBaseView.findViewById(R.id.layout_drawer_left);
mRightDrawerContainer = (ScrollView) rootBaseView.findViewById(R.id.layout_drawer_right);

为了关闭抽屉我尝试了很多方法,它在视觉上关闭了它,我的意思是一切正常,抽屉慢慢离开屏幕并保持关闭状态,但从代码的角度来看它总是返回 true。

 protected boolean isDrawersOpened() {
boolean rightDrawerOpened = mDrawerMainLayout.isDrawerOpen(mRightDrawerContainer);
boolean leftDrawerOpened = mDrawerMainLayout.isDrawerOpen(mLeftDrawerContainer);
return rightDrawerOpened || leftDrawerOpened ;
}

总是正确的

public void closeDrawer() {
mDrawerMainLayout.closeDrawer(GravityCompat.END);
mDrawerMainLayout.closeDrawer(GravityCompat.START);
mDrawerMainLayout.closeDrawer(mRightDrawerContainer);
mDrawerMainLayout.closeDrawer(mLeftDrawerContainer);
mDrawerMainLayout.closeDrawers();
}

所以它应该可以工作,但总是返回 true。

如果它是支持库中的错误,没问题我会等待并在 Activity 中使用 bool 变量来指示这一点,但也许有人处理过同样的问题。

提前感谢任何帮助和想法。

最佳答案

对不起,我的疏忽。
我在我的代码中犯了一个错误

   if (hasLeftDrawer) {
setupLeftDrawer();
} else {
mDrawerMainLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mLeftDrawerContainer);
}
if (hasRightDrawer) {
setupRightDrawer();
} else {
mDrawerMainLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mRightDrawerContainer);
}

应该是

    if (hasLeftDrawer) {
setupLeftDrawer();
} else {
mDrawerMainLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mLeftDrawerContainer);
}
if (hasRightDrawer) {
setupRightDrawer();
} else {
mDrawerMainLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mRightDrawerContainer);
}

关于android - NavigationDrawer isDrawerOpened 总是返回 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32570878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com