Issue
I have textview which contains a part of a text. When the user clicks the arrow, the textview resizes so the full text is shown. See the images below for an example: alt="collapsed">
The TextView has a wrap_content height, and when collapsed a maxLines="4".
The onClick of the arrow contains this code:
if (isExpanded) {
btnToggle.setImageDrawable(getResources().getDrawable(
R.drawable.arrow_down));
tvText.setMaxLines(4);
tvText.setEllipsize(TruncateAt.END);
} else {
btnToggle.setImageDrawable(getResources().getDrawable(
R.drawable.arrow_up));
tvText.setMaxLines(Integer.MAX_VALUE);
tvText.setEllipsize(null);
}
isExpanded = !isExpanded;
This code works, but it is not animated. I need to animate the expansion, so the TextView animates to it's full height. I can't find anything about animating properties like MaxLines. Who can help me out?
Solution
You can achieve this using an ObjectAnimator
ObjectAnimator animation = ObjectAnimator.ofInt(
tvText,
"maxLines",
25);
animation.setDuration(4000);
animation.start();
This will increase the "maxLines" property of the "tvText" TextView from whatever it initially is set to, to 25, over the period of 4000 milliseconds.
Answered By - Ken Wolf
Answer Checked By - David Goodson (JavaFixing Volunteer)