Skip to content

QDBaseSectionLayoutFragment中的可悬停header布局(QDSectionHeaderView)高度如果不一致的话(QDGridSectionAdapter),发现快速滑动的时候有问题,悬停头部的布局错乱。 #1176

@liheng-heng

Description

@liheng-heng

public class QDGridSectionAdapter extends QMUIDefaultStickySectionAdapter<SectionHeader, SectionItem> {

public QDGridSectionAdapter() {
}

public QDGridSectionAdapter(boolean removeSectionTitleIfOnlyOneSection) {
    super(removeSectionTitleIfOnlyOneSection);
}

@NonNull
@Override
protected ViewHolder onCreateSectionHeaderViewHolder(@NonNull ViewGroup viewGroup) {
    return new ViewHolder(new QDSectionHeaderView(viewGroup.getContext()));
}

@NonNull
@Override
protected ViewHolder onCreateSectionItemViewHolder(@NonNull ViewGroup viewGroup) {
    Context context = viewGroup.getContext();
    int paddingHor = QMUIDisplayHelper.dp2px(context, 24);
    int paddingVer = QMUIDisplayHelper.dp2px(context, 16);
    TextView tv = new TextView(context);
    tv.setTextSize(14);
    tv.setBackgroundColor(ContextCompat.getColor(context, R.color.qmui_config_color_gray_9));
    tv.setTextColor(Color.DKGRAY);
    tv.setPadding(paddingHor, paddingVer, paddingHor, paddingVer);
    tv.setGravity(Gravity.CENTER);
    return new ViewHolder(tv);
}

@NonNull
@Override
protected ViewHolder onCreateSectionLoadingViewHolder(@NonNull ViewGroup viewGroup) {
    return new ViewHolder(new QDLoadingItemView(viewGroup.getContext()));
}

@Override
protected void onBindSectionHeader(final ViewHolder holder, final int position, QMUISection<SectionHeader, SectionItem> section) {
    QDSectionHeaderView itemView = (QDSectionHeaderView) holder.itemView;
    itemView.render(section.getHeader(), section.isFold(), position);
    //这里模拟header布局内容不一致的情况
    String pStr = position + "";
    if (pStr.endsWith("3") || pStr.endsWith("4") || pStr.endsWith("5")) {
        itemView.ll_info_1.setVisibility(View.VISIBLE);
        itemView.ll_info_2.setVisibility(View.GONE);
    } else if (pStr.endsWith("6") || pStr.endsWith("7") || pStr.endsWith("8") || pStr.endsWith("9")) {
        itemView.ll_info_1.setVisibility(View.GONE);
        itemView.ll_info_2.setVisibility(View.GONE);
    } else {
        itemView.ll_info_1.setVisibility(View.VISIBLE);
        itemView.ll_info_2.setVisibility(View.VISIBLE);
    }

    itemView.getArrowView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int pos = holder.isForStickyHeader ? position : holder.getAdapterPosition();
            toggleFold(pos, false);
        }
    });
}

@Override
protected void onBindSectionItem(ViewHolder holder, int position, QMUISection<SectionHeader, SectionItem> section, int itemIndex) {
    ((TextView) holder.itemView).setText(section.getItemAt(itemIndex).getText());
}

}

public class QDSectionHeaderView extends LinearLayout {

private TextView mTitle;
public ImageView mArrowView;
public LinearLayout ll_info_1;
public LinearLayout ll_info_2;

public QDSectionHeaderView(Context context) {
    this(context, null);
}

public QDSectionHeaderView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    initLayout();
}

private void initLayout() {
    View view = inflate(getContext(), R.layout.account_book_header, null);
    mTitle = view.findViewById(R.id.mTitle);
    mArrowView = view.findViewById(R.id.mArrowView);
    ll_info_1 = view.findViewById(R.id.ll_info_1);
    ll_info_2 = view.findViewById(R.id.ll_info_2);
    addView(view);
}

public ImageView getArrowView() {
    return mArrowView;
}

public void render(SectionHeader header, boolean isFold, int position) {
    mTitle.setText("标题:" + header.getText());
    mArrowView.setRotation(isFold ? 0f : 90f);
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions