0

I'm using a TextView to be viewed in ListView item, when that item is clicked I need that text to completely be viewed instead of just first 2 lines.

What I'm doing now is changing maxLines value from 2 (the initial value) to the maximum integer value.

I need this to be done with expand animation. I already know how to expand it, but I only need to find the new height such that I can simply call the expand method.

Update: I'm using this code to solve my problem, but the returned full height is smaller than the actual one. I think it's px and dp issue:

public int getFullHeight(TextView tv) {
    Context context = tv.getContext();
    TextView textView = new TextView(context);
    textView.setText(tv.getText().toString());
    textView.setTypeface(tv.getTypeface());
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, tv.getTextSize());
    int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(tv.getLayoutParams().width, View.MeasureSpec.EXACTLY);
    int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(widthMeasureSpec, heightMeasureSpec);
    return textView.getMeasuredHeight();
}

Given that tv is the original TextView that's with 2 lines. If I change COMPLEX_UNIT_PX to COMPLEX_UNIT_DIP then it gets larger than the full size, with a white space at the bottom.

Hamzeh Soboh
  • 7,572
  • 5
  • 43
  • 54

1 Answers1

0

Best solution I can find is this: Measuring text height to be drawn on Canvas ( Android ) Or here: http://egoco.de/post/19077604048/calculating-the-height-of-text-in-android

What they are doing is, creating a paint object with specified width, placing the text and style to use in it and then geting the boundaries.

Hope that helps

Community
  • 1
  • 1
Rene M.
  • 2,660
  • 15
  • 24
  • Sorry I'm not that deep in GUI development. But when you see a pattern in the difference which can be computed like - x pixel by line or so. Then you can compute the difference your self. – Rene M. Apr 01 '15 at 11:20