2015-08-10 8 views
12

मुझे CardView आकार को RecyclerView में रन टाइम पर विस्तार और संक्षिप्त करने की आवश्यकता है। मैं RecyclerView आइटम का उपयोग करने के लिए RecyclerView आइटम और CardView को RecyclerView आइटम के रूप में उपयोग करता हूं। जैसा कि मैं इस अवधारणा के लिए नया हूं कृपया मेरी मदद करें।एंड्रॉइड: रीसाइक्लर में कार्ड व्यू आकार का विस्तार और पतन कैसे करें

उत्तर

13

मैंने रन टाइम पर विस्तार किया है। इस तरह,

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

पर मेरे विचार की स्थापना मैं 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(); 
    } 
} 
+0

विवरण क्या है इस कार्डव्यू में उत्पाद विवरण। इसे – Munchoo

+0

कहां शुरू किया गया है यह एक चर (जैसे कार्ड व्यू) है, आप व्यू आईडी ढूंढकर अपना दृश्य बढ़ा सकते हैं, कहीं भी और इसका वैरिएबल नाम तय कर सकते हैं। – abhishek

संबंधित मुद्दे