Android onLayoutChildren()上的RecyclerView重画内容

Android onLayoutChildren()上的RecyclerView重画内容,android,android-recyclerview,linearlayoutmanager,Android,Android Recyclerview,Linearlayoutmanager,我正在使用一个用于RecyclerView()的自定义LayoutManager,它工作正常,这是用于布局子对象的函数: @Override public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { detachAndScrapAttachedViews(recycler); final int count = this.getItemCount();

我正在使用一个用于RecyclerView()的自定义LayoutManager,它工作正常,这是用于布局子对象的函数:

@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state)
{

    detachAndScrapAttachedViews(recycler);

    final int count = this.getItemCount();
    views.clear();
    lines.clear();
    for (int i = 0; i < count; i++) {
        View child = recycler.getViewForPosition(i);
        addView(child);
        measureChildWithMargins(child, 0, 0);

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        ViewDefinition view = new ViewDefinition(this.config, child);
        view.setWidth(child.getMeasuredWidth());
        view.setHeight(child.getMeasuredHeight());
        view.setNewLine(lp.isNewLine());
        view.setGravity(lp.getGravity());
        view.setWeight(lp.getWeight());
        view.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
        views.add(view);
    }


    this.config.setMaxWidth(this.getWidth() - this.getPaddingRight() - this.getPaddingLeft());
    this.config.setMaxHeight(this.getHeight() - this.getPaddingTop() - this.getPaddingBottom());
    this.config.setWidthMode(View.MeasureSpec.EXACTLY);
    this.config.setHeightMode(View.MeasureSpec.EXACTLY);
    this.config.setCheckCanFit(true);


    CommonLogic.fillLines(views, lines, config);
    CommonLogic.calculateLinesAndChildPosition(lines);


    int contentLength = 0;
    final int linesCount = lines.size();
    for (int i = 0; i < linesCount; i++) {
        LineDefinition l = lines.get(i);
        contentLength = Math.max(contentLength, l.getLineLength());
    }


    LineDefinition currentLine = lines.get(lines.size() - 1);
    int contentThickness = currentLine.getLineStartThickness() + currentLine.getLineThickness();
    int realControlLength = CommonLogic.findSize(this.config.getLengthMode(), this.config.getMaxLength(), contentLength);
    int realControlThickness = CommonLogic.findSize(this.config.getThicknessMode(), this.config.getMaxThickness(), contentThickness);


    CommonLogic.applyGravityToLines(lines, realControlLength, realControlThickness, config);


    for (int i = 0; i < linesCount; i++) {
        LineDefinition line = lines.get(i);
        applyPositionsToViews(line);
    }
}
@覆盖
public void onLayoutChildren(RecyclerView.RecyclerRecycler,RecyclerView.State)
{
拆下和刮下附件(回收器);
final int count=this.getItemCount();
视图。清除();
行。清除();
for(int i=0;i
唯一的问题是,当我调用notifyDataSetChanges()或notifyItemChanges()时,它再次调用onLayoutChildren(),整个recyclerview正在更改它的内容,并向右滚动返回顶部

我试图了解LinearLayoutManager是如何控制这个问题的,但无法如我所希望的那样理解


如何使RecyclerView保持其当前状态,但只更改内容?或者如何滚动到原来的位置?

我也面临类似的问题。你找到解决问题的办法了吗?