How to set layout_span through code

☆樱花仙子☆ 提交于 2019-11-30 16:38:25

问题


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>

回答1:


You can use:

TableRow.LayoutParams params = (TableRow.LayoutParams)editText.getLayoutParams();
params.span = toSpan;
editText.setLayoutParams(params); // causes layout update


来源:https://stackoverflow.com/questions/4637233/how-to-set-layout-span-through-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!