android:expandable list view中的divider属性使android 6.01中的我的应用程序崩溃

android:expandable list view中的divider属性使android 6.01中的我的应用程序崩溃,android,android-fragments,Android,Android Fragments,我不明白为什么当一个可扩展列表视图在带有分隔符设置的对话框片段中膨胀时,我的应用程序会崩溃。它只出现在Android 6.0中。安卓4.2没有问题 expandablelistview.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:id="@+id/filter_layout" android:layout_width="match_parent" android:layout_

我不明白为什么当一个可扩展列表视图在带有分隔符设置的对话框片段中膨胀时,我的应用程序会崩溃。它只出现在Android 6.0中。安卓4.2没有问题

expandablelistview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/filter_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/scroll_layout"
    android:background="#fff"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ExpandableListView
        android:id="@+id/expandable_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/primaryLight"
        android:dividerHeight="5dp"/>
</LinearLayout>
如果删除这两行,则可以打开对话框片段

日志:


正如您可以看到的,您的代码的源代码在以下位置崩溃:

@Override
    void drawDivider(Canvas canvas, Rect bounds, int childIndex) {
        int flatListPosition = childIndex + mFirstPosition;

        // Only proceed as possible child if the divider isn't above all items (if it is above
        // all items, then the item below it has to be a group)
        if (flatListPosition >= 0) {
            final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
            PositionMetadata pos = mConnector.getUnflattenedPos(adjustedPosition);
            // If this item is a child, or it is a non-empty group that is expanded
            if ((pos.position.type == ExpandableListPosition.CHILD) || (pos.isExpanded() &&
                    pos.groupMetadata.lastChildFlPos != pos.groupMetadata.flPos)) {
                // These are the cases where we draw the child divider
                final Drawable divider = mChildDivider;
                divider.setBounds(bounds);
                divider.draw(canvas);
                pos.recycle();
                return;
            }
            pos.recycle();
        }

        // Otherwise draw the default divider
        super.drawDivider(canvas, bounds, flatListPosition);
    }
由于除法器为null或McHildVider为null,您的代码已崩溃

mChildDivder以两种方式接受值:

1-从xml通过:

a.getDrawable(com.android.internal.R.styleable.ExpandableListView_childDivider);
因此,您可以设置:

android:childDivider="..."
2-通过代码:

public void setChildDivider(Drawable childDivider) {
        mChildDivider = childDivider;
    }

您必须使用其中一个来设置McHildVider。

因为您可以在以下位置看到代码崩溃的源代码:

@Override
    void drawDivider(Canvas canvas, Rect bounds, int childIndex) {
        int flatListPosition = childIndex + mFirstPosition;

        // Only proceed as possible child if the divider isn't above all items (if it is above
        // all items, then the item below it has to be a group)
        if (flatListPosition >= 0) {
            final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
            PositionMetadata pos = mConnector.getUnflattenedPos(adjustedPosition);
            // If this item is a child, or it is a non-empty group that is expanded
            if ((pos.position.type == ExpandableListPosition.CHILD) || (pos.isExpanded() &&
                    pos.groupMetadata.lastChildFlPos != pos.groupMetadata.flPos)) {
                // These are the cases where we draw the child divider
                final Drawable divider = mChildDivider;
                divider.setBounds(bounds);
                divider.draw(canvas);
                pos.recycle();
                return;
            }
            pos.recycle();
        }

        // Otherwise draw the default divider
        super.drawDivider(canvas, bounds, flatListPosition);
    }
由于除法器为null或McHildVider为null,您的代码已崩溃

mChildDivder以两种方式接受值:

1-从xml通过:

a.getDrawable(com.android.internal.R.styleable.ExpandableListView_childDivider);
因此,您可以设置:

android:childDivider="..."
2-通过代码:

public void setChildDivider(Drawable childDivider) {
        mChildDivider = childDivider;
    }
您必须使用其中一个来设置McHildVider