使用NestedScrollView时“应用程序没有响应”

时间:2017-03-27 10:19:48

标签: android android-layout android-viewpager android-recyclerview

我不知道为什么但是当我使用NestedScrollView时,我的应用程序开始挂起,然后出现“应用程序没有响应”弹出窗口。我甚至没有在日志中收到任何错误。这是XML代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/srlFeed"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="true"
            android:orientation="vertical">

            <in.mylo.pregnancy.baby.CustomSpinner
                android:id="@+id/spinner"
                style="@style/Widget.AppCompat.Spinner"
                android:layout_width="120dp"
                android:layout_height="?attr/dropdownListPreferredItemHeight"
                android:layout_margin="10dp"
                android:background="@drawable/spinner_bg"
                android:dropDownVerticalOffset="?attr/dropdownListPreferredItemHeight"
                android:dropDownWidth="200dp"
                android:paddingRight="14dp"
                android:popupBackground="@android:color/white"
                android:popupElevation="2dp"
                android:stateListAnimator="@drawable/spinner_sla" />

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

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/rvFeed"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/pbLoadMore"
                    android:scrollbars="none" />

                <ProgressBar
                    android:id="@+id/pbLoadMore"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:visibility="gone" />
            </RelativeLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <LinearLayout
        android:id="@+id/llEmptyLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">

        <ImageView
            android:layout_width="72dp"
            android:layout_height="54dp"
            android:src="@drawable/blush" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"
            android:text="Your feed will appear here"
            android:textSize="16sp" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/llAccessDeniedLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:gravity="center"
            android:text="To access, tell us your due date &amp; create\naccount"
            android:textSize="16sp" />

        <LinearLayout
            android:id="@+id/llCreateAccount"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:background="@drawable/ic_btn_feedback_pink"
            android:gravity="center"
            android:orientation="vertical"
            android:paddingBottom="10dp"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingTop="10dp">

            <TextView
                style="@style/MTS_ExtraSmall_1.Light"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Create account"
                android:textSize="16sp" />
        </LinearLayout>
    </LinearLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabQA"
        android:layout_width="36dp"
        android:layout_height="36dp"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="116dp"
        android:layout_marginRight="@dimen/material_layout_margin"
        android:src="@drawable/up_arrow_small"
        android:visibility="gone"
        app:backgroundTint="@color/arrow_splash"
        app:fabSize="mini" />
</RelativeLayout>

当我删除NestedScrollView时,该应用程序正常工作。我不知道我做错了什么?这是我在日志上得到的:

16:00:07.070 14426-14437/in.mylo.pregnancy.baby.app I/art: Backgroundsticky concurrent mark sweep GC freed 133954(7MB) AllocSpace objects,3(48KB) LOS objects, 7% free, 93MB/101MB, paused 2.393ms total158.307ms
03-27 16:00:09.233 14426-14433/in.mylo.pregnancy.baby.app W/art:Suspending all threads took: 97.543ms
03-27 16:00:09.266 14426-14437/in.mylo.pregnancy.baby.app W/art:Suspending all threads took: 32.883ms
03-27 16:00:09.338 14426-14437/in.mylo.pregnancy.baby.app I/art:Background partial concurrent mark sweep GC freed 206445(16MB)AllocSpace objects, 0(0B) LOS objects, 15% free, 84MB/100MB, paused35.005ms total 284.141ms
03-27 16:00:20.769 14426-14432/in.mylo.pregnancy.baby.app I/art:Thread[3,tid=14432,WaitingInMainSignalCatcherLoop,Thread*=0xa4562700,peer=0x12c050d0,"Signal Catcher"]: reacting to signal 3
03-27 16:00:20.969 14426-14432/in.mylo.pregnancy.baby.app I/art: Wrotestack traces to '/data/anr/traces.txt'

1 个答案:

答案 0 :(得分:0)

此行为似乎与缺少的依赖项有关。您是否以compile 'com.android.support:recyclerview-v7:22.2.0'为例或配置了其他依赖项(例如“in.mylo.pregnancy.baby.CustomSpinner”不可用)?

更新

重要的一点我在你的日志中注意到,我看到很多内存消耗。可能是应用程序也在执行一些后台逻辑。我的建议是尝试在没有“in.mylo.pregnancy.baby.CustomSpinner”的情况下运行你的app,看看它是否会导致这个问题发生。

希望这有帮助。