Example usage for android.widget TextView getMaxHeight

List of usage examples for android.widget TextView getMaxHeight

Introduction

In this page you can find the example usage for android.widget TextView getMaxHeight.

Prototype

public int getMaxHeight() 

Source Link

Document

Returns the maximum height of TextView in terms of pixels or -1 if the maximum height was set using #setMaxLines(int) or #setLines(int) .

Usage

From source file:Main.java

public static void animateTextViewMaxLinesChange(final TextView textView, final int maxLines,
        final int duration) {
    final int startHeight = textView.getMeasuredHeight();
    textView.setMaxLines(maxLines);/*from  w w w  .jav a 2s  .  c o  m*/
    textView.measure(View.MeasureSpec.makeMeasureSpec(textView.getWidth(), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    final int endHeight = textView.getMeasuredHeight();
    ObjectAnimator animation = ObjectAnimator.ofInt(textView, MAX_HEIGHT_ATTR, startHeight, endHeight);
    animation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (textView.getMaxHeight() == endHeight) {
                textView.setMaxLines(maxLines);
            }
        }
    }

    );
    animation.setDuration(duration).start();
}