浓咖啡检查在回收站视图标题中添加的文本作为项装饰

时间:2019-01-05 21:36:17

标签: android canvas android-recyclerview android-espresso item-decoration

所以我有一个回收站视图,我需要向其中添加项目作为节或标题。我正在使用回收器视图的ItemDecorations onDrawOver方法实现此目的,因此将其写入画布并像这样插入

 private void drawHeader(Canvas c, View child, View headerView) {
    c.save();
    if (sticky) {
        c.translate(0, Math.max(0, child.getTop() - headerView.getHeight()));
    } else {
        c.translate(0, child.getTop() - headerView.getHeight());
    }
    headerView.draw(c);
    c.restore();
}

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDrawOver(c, parent, state);

    if (headerView == null) {
        headerView = inflateHeaderView(parent);
        header = (TextView) headerView.findViewById(R.id.title);
        fixLayoutSize(headerView, parent);
    }

    CharSequence previousHeader = "";
    for (int i = 0; i < parent.getChildCount(); i++) {
        View child = parent.getChildAt(i);
        final int position = parent.getChildAdapterPosition(child);

        String title = sectionCallback.getSectionHeader(position);
        header.setText(title);
        if (!previousHeader.equals(title) || sectionCallback.isSection(position)) {
            drawHeader(c, child, headerView);
            previousHeader = title;
        }
    }
}

private View inflateHeaderView(RecyclerView parent) {
    return LayoutInflater.from(parent.getContext())
            .inflate(R.layout.request_sticky_header, parent, false);
}

我正在为此编写测试,但是由于“找不到层次结构中的视图与文本匹配:”而崩溃,我在层次结构中看不到文本,我想知道是否是因为布局被绘制到在画布上,有人可以帮我检查一下是否已添加视图吗?

视图在那里,我可以看到它,我只是想要一个测试证明它,如果不可能的话就依靠手动检查和屏幕截图

0 个答案:

没有答案