我正在尝试在我的应用中为用户个人资料屏幕创建类似的布局。 这就是我需要的: 1.后退,加号和图像按钮应位于工具栏中的折叠状态和展开状态。 2.工具栏在展开状态下应该是透明的,并在折叠时更改为内容稀松布的颜色。 3.服务(180)和熟(300)文本应该是可点击的,并导致其他活动。 4.在折叠时,tabLayout应固定在工具栏下方。 5.附加到选项卡的ViewPager应该可以正常工作,它包含listview。
这是我的尝试:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#231f20"
android:fitsSystemWindows="true">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
android:background="#231f20"
app:layout_anchor="@+id/appbar"
app:layout_anchorGravity="bottom"
app:tabGravity="fill"
app:tabMode="fixed" />
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="#FAC80A"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="200dp"
app:expandedTitleMarginBottom="110dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax">
// Contains the background image, profile pic,textview etc.
</RelativeLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
问题:在开始时点击折叠工具栏的内容(相对布局内)中的任何位置都不会引起任何问题,但只要我进行一些滚动(折叠工具栏,滚动浏览器内容,更改标签)和再次回到展开状态的折叠工具栏,然后单击它上面的任意位置,应用程序崩溃。我收到以下错误:
09-21 07:28:38.740 5462-5462/com.galleri5.android E/InputEventReceiver﹕ Exception dispatching input event.
09-21 07:28:38.741 5462-5462/com.galleri5.android E/MessageQueue-JNI﹕ Exception in MessageQueue callback: handleReceiveCallback
09-21 07:28:38.744 5462-5462/com.galleri5.android E/MessageQueue-JNI﹕ java.lang.NullPointerException: Attempt to invoke virtual method 'float android.view.MotionEvent.getX()' on a null object reference
at android.view.View.onTouchEvent(View.java:9321)
at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:449)
at android.view.View.dispatchTouchEvent(View.java:8388)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2569)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1743)
at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2530)
at android.view.View.dispatchPointerEvent(View.java:8578)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4028)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3894)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3585)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5708)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5682)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5653)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5798)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
09-21 07:28:38.747 5462-5462/com.galleri5.android E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.galleri5.android, PID: 5462
java.lang.NullPointerException: Attempt to invoke virtual method 'float android.view.MotionEvent.getX()' on a null object reference
at android.view.View.onTouchEvent(View.java:9321)
at android.support.design.widget.CoordinatorLayout.onTouchEvent(CoordinatorLayout.java:449)
at android.view.View.dispatchTouchEvent(View.java:8388)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2424)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2158)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2119)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2569)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1743)
at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:60)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2530)
at android.view.View.dispatchPointerEvent(View.java:8578)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4028)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3894)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3585)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3642)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3509)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3475)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3483)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3456)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5708)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5682)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5653)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5798)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
此行为的原因是什么?如何纠正此问题。
答案 0 :(得分:0)
这是android support library
的问题。
请参阅此链接了解详情CoordinatorLayout NullPointerException in onTouchEvent
根据上述链接,此问题已在android support library version-23.0.1
更新您的Android支持库以解决错误。