2015-08-10 24 views

Odpowiedz

13

Mam rozszerzenie w czasie wykonywania. tak,

Ustawianie mój pogląd na 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; 
} 
}); 

i onClickingcardview

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

jestem ustawienie CardView wysokości, aby rozwijać i zwijać.

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(); 
    } 
} 
+0

co to jest detailProductDescription w tym cardview. gdzie jest on zainicjalizowany – Munchoo

+0

Jest to zmienna (jak widok karty), możesz nadmuchać swój widok, znajdując identyfikator widoku, dowolne miejsce i decydując o nazwie zmiennej. – abhishek

Powiązane problemy