Reputation: 157
Adding text view to row and thus row to table layout. But the row gets cut from the screen.
TextView point = new TextView(activity);
TextView time = new TextView(activity);
point.setTextSize(15);
time.setTextSize(15);
point.setPadding(5, 5, 5, 5);
time.setPadding(5, 5, 5, 5);
point.setText("smthing something")
time.setText("smthing smthing")
row.addView(point);
row.addView(time);
tableLayout.addView(row);
How to wrap the textview in the row so that the row gets wrapped in the screen itself..?
Upvotes: 1
Views: 1273
Reputation: 157
Thanks Mukesh, that solved most of the part of my problem. :) The text crossing the screen got wrapped inside screen. Since my first column contained long text and second column has short text.. So first column must fit in multiple lines and 2nd column in single line. (Setting the textview to single line or multiple line didnt help)
So I did it by adding shrink column to my '0th' and stretch column to my '1st'. This solved my whole problem and setting layout params also not required now.
XML for table layout:
<TableLayout
android:id="@+id/route_table"
android:layout_width="match_parent"
android:shrinkColumns="0"
android:padding="5dp"
android:stretchColumns="1">
<TableRow android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/row1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/stop"
android:background="@drawable/table_row"
android:padding="10dp"
android:text="Stop: "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/time"
android:layout_gravity="right"
android:background="@drawable/table_row"
android:padding="10dp"
android:text="Time: "/>
</TableLayout>
`
Upvotes: 1
Reputation: 258
Set your textView height wrap_content.
point.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Upvotes: 1
Reputation: 1411
TextView point = new TextView(activity);
TextView time = new TextView(activity);
LayoutParams layoutParams = new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
point.setLayoutParams(layoutParams);
time.setLayoutParams(layoutParams);
point.setTextSize(15);
time.setTextSize(15);
point.setPadding(5, 5, 5, 5);
time.setPadding(5, 5, 5, 5);
point.setText("smthing something")
time.setText("smthing smthing")
row.addView(point);
row.addView(time);
tableLayout.addView(row);
Upvotes: 0