2017-07-18 15 views
3

RecyclerviewにLinearSnapHelperが添付されたフラグメントがあるので、ビューを中央に取得し、サイズを拡大して強調表示します。RecyclerView#onMeasure()は、setMeasuredDimension()を呼び出すことで測定ディメンションを設定しませんでした。

これはうまくいきますが、この断片をバックプレスのバックスタックからポップすると、以下の例外がスローされます。 recyclerviewため

E/UncaughtException: java.lang.IllegalStateException: View with id 2131689939: android.support.v7.widget.RecyclerView#onMeasure() did not set the measured dimension by calling setMeasuredDimension() 
                    at android.view.View.measure(View.java:19746) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
                    at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1117) 
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:642) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
                    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
                    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 
                    at android.view.View.measure(View.java:19734) 
                    at android.support.v4.widget.NestedScrollView.measureChildWithMargins(NestedScrollView.java:1420) 
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
                    at android.support.v4.widget.NestedScrollView.onMeasure(NestedScrollView.java:482) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714) 
                    at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90) 
                    at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1391) 
                    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784) 
                    at android.view.View.measure(View.java:19734) 
                    at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1081) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
                    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
                    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464) 
                    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758) 
                    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120) 
                    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185) 
                    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687) 
                    at android.view.View.measure(View.java:19734) 
                    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271) 
                    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358) 
                    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607) 

relavantコードは、我々はすでにRecyclerViewを持ってLayoutManagerRecyclerView.setLayoutManager()を呼び出すためであると

として

https://gist.githubusercontent.com/anonymous/81a2ae091ded158839b6353ddb03163f/raw/1aff18064d4de4e42b79aa50ff8d44bd6df365a9/Main.java

+0

見つけましたか? –

答えて

2

私の事です。

public void setLayoutManager(LayoutManager layout) { 
    ... 
    if (layout != null) { 
     if (layout.mRecyclerView != null) { 
      throw new IllegalArgumentException("LayoutManager " + layout 
        + " is already attached to a RecyclerView:" 
        + layout.mRecyclerView.exceptionLabel()); 
     } 
     mLayout.setRecyclerView(this); 
     if (mIsAttached) { 
      mLayout.dispatchAttachedToWindow(this); 
     } 
    } 
    ... 
} 

しかし、私は理解していない理由のために、Logcatに印刷された例外は

UncaughtException: java.lang.IllegalStateException: View with id 2131231433: android.support.v7.widget.RecyclerView#onMeasure() did not set the measured dimension by calling setMeasuredDimension()` 

あるかもしれない何かが、この例外とスローは(原因なし)の代わりにこれをキャッチ?

+0

はい。レイアウトマネージャを再初期化する必要がありました。ありがとう!! –

関連する問題