Подтвердить что ты не робот

Android: как развернуть и свернуть размер карты в RecyclerView

Мне нужно развернуть и свернуть размер CardView в RecyclerView во время выполнения. Я использую RecyclerView для отображения списка и CardView как RecyclerView Item. Поскольку я новичок в этой концепции, пожалуйста, помогите мне.

4b9b3361

Ответ 1

Я расширяю время выполнения. например,

Настройка моего представления на onCreateView()

descriptionCardView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver
    .OnPreDrawListener() {
@Override
public boolean onPreDraw() {
    detailProductDescription.getViewTreeObserver().removeOnPreDrawListener(this);
    // save the full height
    descriptionViewFullHeight = detailProductDescription.getHeight();

    // initially changing the height to min height
    ViewGroup.LayoutParams layoutParams = descriptionCardView.getLayoutParams();
    layoutParams.height = (int) getActivity().getResources().getDimension(R.dimen
            .product_description_min_height);
    descriptionCardView.setLayoutParams(layoutParams);

    return true;
 }
});

и onClickingcardview

@OnClick(R.id.detail_product_description)
void onProductDescriptionClicked(View view) {
    toggleProductDescriptionHeight();
}

Я устанавливаю Height CardView для расширения и сглаживания.

private int descriptionViewFullHeight;    
private void toggleProductDescriptionHeight() {

    int descriptionViewMinHeight = (int) getActivity().getResources().getDimension(R.dimen
            .product_description_min_height);
    if (descriptionCardView.getHeight() == descriptionViewMinHeight) {
        // expand
        ValueAnimator anim = ValueAnimator.ofInt(descriptionCardView.getMeasuredHeightAndState(),
                descriptionViewFullHeight);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = descriptionCardView.getLayoutParams();
                layoutParams.height = val;
                descriptionCardView.setLayoutParams(layoutParams);
            }
        });
        anim.start();
    } else {
        // collapse
        ValueAnimator anim = ValueAnimator.ofInt(descriptionCardView.getMeasuredHeightAndState(),
                descriptionViewMinHeight);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int val = (Integer) valueAnimator.getAnimatedValue();
                ViewGroup.LayoutParams layoutParams = descriptionCardView.getLayoutParams();
                layoutParams.height = val;
                descriptionCardView.setLayoutParams(layoutParams);
            }
        });
        anim.start();
    }
}