【问题标题】:"App isn't responding" when use NestedScrollView使用 NestedScrollView 时“应用程序没有响应”
【发布时间】:2017-03-27 10:19:48
【问题描述】:

我不知道为什么,但是当我使用 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'

【问题讨论】:

  • 在崩溃期间发布 logcat 堆栈跟踪...
  • @rafsanahmad007 没有收到任何错误,但我仍然发布了 logcat。
  • 在活动中使用严格模式来确定主线程被阻塞的原因和位置。

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


【解决方案1】:

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

更新

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

希望这会有所帮助。

【讨论】:

  • 我已经添加了该依赖项。如果我没有,我将无法使用 recyclerView
  • 它在我这边工作正常,你能分享你的“com.android.support”依赖吗?
  • 我使用的是 25.0.2 版
  • 您能否查看我关于在后台运行的逻辑导致应用程序卡住的更新?
猜你喜欢
  • 2017-04-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多