【问题标题】:IllegalArgumentException parameter must be a descendant of this view at ViewGroup.offsetRectBetweenParentAndChildIllegalArgumentException 参数必须是 ViewGroup.offsetRectBetweenParentAndChild 处此视图的后代
【发布时间】:2014-11-05 07:56:38
【问题描述】:

我的一位应用程序用户在崩溃日志中出现以下异常。无法从日志跟踪中理解。如果有人有什么想法,请分享。

致命异常:java.lang.IllegalArgumentException 参数必须是该视图的后代 生的

android.view.ViewGroup.offsetRectBetweenParentAndChild (ViewGroup.java:4563) android.view.ViewGroup.offsetDescendantRectToMyCoords (ViewGroup.java:4500) android.view.ViewGroup$ViewLocationHolder.init (ViewGroup.java:6738) android.view.ViewGroup$ViewLocationHolder.obtain (ViewGroup.java:6675) android.view.ViewGroup$ChildListForAccessibility.init (ViewGroup.java:6633) android.view.ViewGroup$ChildListForAccessibility.obtain (ViewGroup.java:6601) android.view.ViewGroup.addChildrenForAccessibility (ViewGroup.java:1703) android.view.ViewGroup.onInitializeAccessibilityNodeInfoInternal (ViewGroup.java:2530) android.view.View.onInitializeAccessibilityNodeInfo (View.java:5209) android.widget.AdapterView.onInitializeAccessibilityNodeInfo (AdapterView.java:937) android.widget.AbsListView.onInitializeAccessibilityNodeInfo (AbsListView.java:1492) android.widget.ListView.onInitializeAccessibilityNodeInfo (ListView.java:3781) android.view.View.createAccessibilityNodeInfoInternal (View.java:5170) android.view.View.createAccessibilityNodeInfo (View.java:5157)

【问题讨论】:

  • 请贴出代码

标签: android android-viewgroup


【解决方案1】:

我通过添加这样的自定义侦听器来修复此错误:

protected class MyScrollListener implements OnScrollListener {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                int visibleItemCount, int totalItemCount) {
            // do nothing 
        }

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if (SCROLL_STATE_TOUCH_SCROLL == scrollState) {
                View currentFocus = getCurrentFocus();
                if (currentFocus != null) {
                    currentFocus.clearFocus();
                }
            }
        }

    }

然后使用你创建的监听器:

listview.setOnScrollListener(MyScrollListener);

有关更多信息,请参阅此(代码也取自此链接):Preventing/catching "IllegalArgumentException: parameter must be a descendant of this view" error

【讨论】:

  • 问题是我的应用程序中有多个ListViews,并且收到的崩溃日志没有关于导致崩溃的日志的信息。
  • @Ammar 是的,我知道你的感受。我把它放在我所有的列表视图上。不幸的是,我不知道任何更简单的解决方案。
【解决方案2】:

我尝试调用 EditText 小部件的 clearFocus() 成员,但这对我不起作用。然而,真正起作用的是调用父级的 clearChildFocus(View) 函数。 代码如下:

ViewParent parent = mEditText.getParent();
parent.clearChildFocus(mEditText);

【讨论】:

  • 对我有用,但很担心,因为我不知道它为什么会起作用。谁能解释一下?
【解决方案3】:

这对我有用。

convertView = mInflater.inflate(R.layout.row_stat_header,
                    parent, false); 

这里parent是getView中的ViewGroup参数。

【讨论】:

    【解决方案4】:

    当我尝试将 edittext 与 recyclerview 一起使用时,我遇到了同样的错误。我认为这同样适用于使用 listview 的 editext。

    当 Viewgroup 处理视图时出现焦点不匹配时会出现问题。对我来说,解决问题的方法是将 android:windowSoftInputMode="adjustPan" 添加到相关活动的清单中。

    <activity android:name=".register.RegistrationActivity"
            android:windowSoftInputMode="adjustPan"/>
    

    希望这对某人有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-29
      • 2022-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      相关资源
      最近更新 更多