【发布时间】:2018-07-22 19:33:30
【问题描述】:
我在 NestedScrollView 中有 ViewPager,为了让我的 ViewPager 附加正确的高度和滚动属性,我将 android:nestedScrollingEnabled="true" 添加到我的NestedScroll..,这是我的设计:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<items .... />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nestedScroll"
android:nestedScrollingEnabled="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_7sdp"
android:layout_marginRight="@dimen/_7sdp"/>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
问题:当我将 android:nestedScrollingEnabled="true" 设置为 true 时,我得到了这些异常:
java.lang.RuntimeException: Unable to start activity ComponentInfo{somePackege}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
与
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.NestedScrollingChildHelper.setNestedScrollingEnabled(boolean)' on a null object reference
如果android:nestedScrollingEnabled="@otherAtt" 采用另一个属性(不是boolean),我会感到困惑。
我想知道是否有更好的方法来实现这种行为。
【问题讨论】:
标签: android android-viewpager android-coordinatorlayout android-nestedscrollview