I have a ListView. Initially, the ListView contains some data. When the user clicks on an item, another layout will be dynamically added to that it
Using value animator the solution looks nice:
ValueAnimator animator = ValueAnimator.ofInt(100, 300);
animator.setDuration(1000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
listViewItem.getLayoutParams().height = (Integer) animation.getAnimatedValue();
listViewItem.requestLayout();
}
});
animator.start();
Just read the android developer guide, it is worth reading: http://developer.android.com/guide/topics/graphics/prop-animation.html
But keep in mind, that requestLayout() processing is heavy. Because one call of requestLayout() make every nearby element, which is visually affected, recalculate it's layout. It may be better to use negative bottom margin (to hide some part of your element under another one) and use the following to show it:
listViewItem.setTranslationY((Integer) animation.getAnimatedValue());
Of course, you may animate only bottom margin, like proposed in another answer to this question.