I have a RecyclerView
in my android project, it has 2 LinearLayout
in each row.
first I want that one of those layouts got Gone. after I click on row it get visible with animation. in short I want to implement a expandable RecyclerView without any external libraries. can you give me a solution to do this?
I wanted to achieve this by animating hoder.itemView 's Height. but actually I didn't know what to insert instead of????
because at first I don't know it's height.
if(holder.layout2.getVisibility() == View.Gone) {
holder.layout2.setVisibility( View.VISIBLE );
animateHeight(holder.itemView,?????);
}
else {
animateHeight(holder.itemView,holder.itemView.getHeight - holder.layout2.getHeight());
holder.layout2.setVisibility( View.GONE );
}
public void animateHeight(final View v, final int height) {
final int initialHeight = v.getMeasuredHeight();
int duration = 500;
Interpolator interpolator = new AccelerateInterpolator();
// I have to set the same height before the animation because there is a glitch
// in the beginning of the animation
v.getLayoutParams().height = initialHeight;
final int diff = height - initialHeight;
v.requestLayout();
Animation a = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
v.getLayoutParams().height = initialHeight + (int) (diff * interpolatedTime);
v.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
a.setDuration(duration);
a.setInterpolator(interpolator);
v.startAnimation(a);
}