Text overflow in textview in android

How to make the text of textview to fill only the width and to start a new line in case the text overflow the width of the screen ? I am trying to add the control from java code :

contentTable = (TableLayout) findViewById(R.id.contentTable);

            TableRow row = new TableRow(getApplicationContext());       
            TextView tv1 = new TextView(getApplicationContext());
            TextView tv2 = new TextView(getApplicationContext());

            tv1.setGravity(Gravity.RIGHT);
            tv2.setGravity(Gravity.RIGHT);

            row.setGravity(Gravity.RIGHT);


            tv1.setTextColor(Color.BLACK);
            tv2.setTextColor(Color.BLACK);


            tv1.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f));
            tv2.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f));

            tv1.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
            tv2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);


            tv1.setText(recipe.ingredients.get(i).name));
            tv2.setText(" "+recipe.ingredients.get(i).quantity);


            setTypeFace(tv1,tv2);

            row.addView(tv1);
            row.addView(tv2);

            contentTable.addView(row);

Answers


layout_width="match_parent" or specific dp width, layout_height="wrap_content" and that is it, I think.


The TableLayout android:shrinkColumns attribute allows to list the index of the columns to shrink (zero-based). It will remove unnecessary extra space from a column (considering all rows) and shrink it. It enables text wrapping to multi-line for the specified columns.

<TableLayout 
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:shrinkColumns="0,1" />

Need Your Help

change font size of facet titles using seaborn facetgrid heatmap

python matplotlib seaborn

Note: this is a different question than "How can I change the font size using seaborn FacetGrid?". The methods suggested there do not work when using a heatmap inside a facetgrid.

Plotting Logscale in R's curve()

r plot

I have a data which I want to plot in cumulative function.