gpt4 book ai didi

android - Navigation Drawer,关闭特殊区域的bug

转载 作者:行者123 更新时间:2023-11-30 03:25:40 31 4
gpt4 key购买 nike

当我触摸这个区域时,我得到了强制关闭: enter image description here一个人很伤心,这里没有 .closeDrawer();我不知道,我必须在哪里创建它。这是我的日志:

08-17 20:18:28.275: E/InputEventReceiver(24620): Exception dispatching input event.
08-17 20:18:28.275: E/MessageQueue-JNI(24620): Exception in MessageQueue callback: handleReceiveCallback
08-17 20:18:28.285: E/MessageQueue-JNI(24620): java.lang.NullPointerException
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:805)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:831)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1854)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.View.dispatchPointerEvent(View.java:7564)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.MessageQueue.nativePollOnce(Native Method)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.MessageQueue.next(MessageQueue.java:132)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.os.Looper.loop(Looper.java:124)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at java.lang.reflect.Method.invoke(Method.java:525)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-17 20:18:28.285: E/MessageQueue-JNI(24620): at dalvik.system.NativeStart.main(Native Method)
08-17 20:18:28.285: D/AndroidRuntime(24620): Shutting down VM
08-17 20:18:28.285: W/dalvikvm(24620): threadid=1: thread exiting with uncaught exception (group=0x417fd700)
08-17 20:18:28.295: E/AndroidRuntime(24620): FATAL EXCEPTION: main
08-17 20:18:28.295: E/AndroidRuntime(24620): java.lang.NullPointerException
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.support.v4.widget.DrawerLayout.isContentView(DrawerLayout.java:805)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:831)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1854)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2211)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1912)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.View.dispatchPointerEvent(View.java:7564)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.MessageQueue.nativePollOnce(Native Method)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.MessageQueue.next(MessageQueue.java:132)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.os.Looper.loop(Looper.java:124)
08-17 20:18:28.295: E/AndroidRuntime(24620): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-17 20:18:28.295: E/AndroidRuntime(24620): at java.lang.reflect.Method.invokeNative(Native Method)
08-17 20:18:28.295: E/AndroidRuntime(24620): at java.lang.reflect.Method.invoke(Method.java:525)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-17 20:18:28.295: E/AndroidRuntime(24620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-17 20:18:28.295: E/AndroidRuntime(24620): at dalvik.system.NativeStart.main(Native Method)

这是抽屉 xml:

    <ListView
android:id="@+id/left_drawer"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#E3E9E3"
android:dividerHeight="1dp"
android:showDividers="middle"
android:background="#F3F3F4"/>
</android.support.v4.widget.DrawerLayout>

这是我的代码:

import com.mdev.learnit.helpprogramms.Calculator;
import com.mdev.learnit.settings.AboutActivity;
import com.mdev.learnit.settings.SettingsActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class StartActivity extends Activity {

private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;

private CharSequence mDrawerTitle;
private CharSequence mTitle;
private String[] mPlanetTitles;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_main);

mTitle = mDrawerTitle = getTitle();
mPlanetTitles = getResources().getStringArray(R.array.drawer_names);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);

// добавляем тень к открытому Navigation Drawer

mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

// прописываем адаптер к нашему списку

mDrawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_text, mPlanetTitles));

mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

// делаем иконку приложения кликабельной

getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);

// конфигурируем нашу икноку, добавляем текст для открытия/закрытия, добавляем дополнительное изображение, которое будет обозначать открыт ли Navigation Drawer или же он закрыт

mDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
R.drawable.ic_drawer_white,
R.string.drawer_open,
R.string.drawer_close
) {
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}

public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);


}

private class DrawerItemClickListener implements ListView.OnItemClickListener {

@Override
public void onItemClick(AdapterView parent, View view, int position,long id) {
switch(position) {
case 0:
Intent a = new Intent(StartActivity.this, AlgebraTheoryActivity.class);
startActivity(a);
break;
case 1:
Intent b = new Intent(StartActivity.this, Calculator.class);
startActivity(b);
break;
case 2:
Intent c = new Intent(StartActivity.this, SettingsActivity.class);
startActivity(c);
break;
case 3:
Intent d = new Intent(StartActivity.this, AboutActivity.class);
startActivity(d);
break;
default:
}
}
}

@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}


@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

public boolean onOptionsItemSelected(MenuItem item) {
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}

}

*对不起俄罗斯评论

一个人很伤心,这里没有 .closeDrawer();我不知道,我必须在哪里创建它。

请帮帮我

最佳答案

根据 Android Doc about create an Navigation Drawer您需要创建 android.support.v4.widget.DrawerLayout 作为您布局的根目录,其中包含两个 subview :FragmentLayoutListView

因为 XML 顺序暗示了 z 顺序并且抽屉必须位于内容之上。

如果你不需要使用 FragmentLayout View ,你可以让它的可见性消失

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

<!-- Framelayout to display Fragments -->
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />

<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>

如果您需要创建多个FragmentLayout,您可以创建RelativeLayoutLinearLayout 作为第一个子项android.support.v4.widget.DrawerLayout Root View

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

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

<FrameLayout android:id="@+id/fragment_first"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</FrameLayout>

<FrameLayout android:id="@+id/fragment_second"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_belo="@id/fragment_first" >

</FrameLayout>

</RelativeLayout>

<!-- Listview to display slider menu -->
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>

关于android - Navigation Drawer,关闭特殊区域的bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18291478/

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