Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set layout_span through code

Tags:

Does anyone know how to set/change the android:layout_span="" of an EditText in Android at runtime. I already have the EditText defined in my XML file.

<TableRow android:paddingTop="20dip" android:gravity="center_horizontal">        <EditText android:layout_width="150dip"           android:text=""          android:layout_height="40dip"           android:id="@+id/p"          android:layout_span="2">     </EditText>  </TableRow> 
like image 308
L4N0 Avatar asked Jan 09 '11 01:01

L4N0


People also ask

What is layout_ span in Android?

android:layout_span. Defines how many columns this child should span.

What is layout params?

This set of layout parameters defaults the width and the height of the children to ViewGroup. LayoutParams. WRAP_CONTENT when they are not specified in the XML file. RelativeLayout.LayoutParams. Specifies how a view is positioned within a RelativeLayout .

What is layout span?

Stretching layout using Layout SpansThe amount of space given to each element, is specified in the android:layout_span attribute, which tells us how many columns it will span over.


1 Answers

You can use:

TableRow.LayoutParams params = (TableRow.LayoutParams)editText.getLayoutParams(); params.span = toSpan; editText.setLayoutParams(params); // causes layout update 
like image 150
Rich Schuler Avatar answered Oct 19 '22 14:10

Rich Schuler