Animate MaxLines and Ellipsize

前端 未结 4 1150
误落风尘
误落风尘 2020-12-13 06:51

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:

4条回答
  •  眼角桃花
    2020-12-13 07:41

    While animating maxLines works, the result is a bit choppy since your view height jumps a lot.

    int startHeight = content.getMeasuredHeight();
    content.setMaxLines(Integer.MAX_VALUE);
    content.measure(
                View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.AT_MOST),
                View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    int endHeight = content.getMeasuredHeight();
    

    content is a TextView with maxLines set to 2. Now you can animate the TextView height instead. Edit: TextView scrolls when it can't fit it's content vertically, you'll need workarounds. setMovementMethod(null) disables scrolling, but it also disables link clicking. Because Android.

提交回复
热议问题