Click here to Skip to main content
15,937,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Gurus,

I have some critical issue related to height of TextView. I want to set the height of the TextView based on the content which is set at runtime.

Here is my xml code:-
 < TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/ >



Here is the java code to set the height of the TextView:-

TextView tv = (TextView) findViewById(R.id.tv);
tv.invalidate();
int height_in_pixels = tv.getLineCount() * tv.getLineHeight();
tv.setHeight(height_in_pixels);



But the problem is; it displays only 1 line, and not the rest of the lines.
Posted
Updated 19-Sep-18 4:39am

1 solution

Friends, 
Use this way :


<pre lang="xml">
<TextView
   android:id="@+id/tv"
   android:layout_width="fill_parent"
   android:layout_height="15dp" <!-- HEIGHT only example -->
   android:autoSizeTextType="uniform"/>
 
Share this answer
 
v2
Comments
David Crow 20-Sep-18 9:37am    
Just curious, but why make a comment on a post that was created over 8 years ago?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900