Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed size textview in table layout

Tags:

android

I have table using table layout. I added the textview in it. I have shape drawable for each column. I defined the size in there.

<size android:width="100dp" android:height="50dp"/>

In column, there is a textview. My table will be generated by programmatically. When the text in text view is long, the column in table become large and there is no space for other column. I would like to enter new line if there is no space for text. the textview is depend on its text size. I want the fixed size of textview in a column. I have tried other posts but no luck.

Thanks.

like image 732
user1156041 Avatar asked May 07 '13 10:05

user1156041


2 Answers

Keep the width of the text view fixed and height as wrap content

<TextView android:id="@+id/sampleText"
  android:layout_width="100dip" 
  android:layout_height="wrap_content"
  android:maxLines="4" 
  android:singleLine="false">
</TextView> 
like image 67
Anirudha Agashe Avatar answered Oct 02 '22 01:10

Anirudha Agashe


I found one solution for my requirement. I made fixed size column and scrollable textview. Firstly I remove size tag from shape drawable resource. And I add the following code for each column.

LayoutParams params = new TableRow.LayoutParams(100, 50);

I add the linear layout for each column and add scrollview into it. And then I add the textview in the scrollview. Actually I cannot know the length of text. Because the length of size may be vary, I choose this solution.

like image 41
user1156041 Avatar answered Oct 02 '22 00:10

user1156041