2013-03-03 89 views
2

我有一个textView,我试图在运行时更改大小。但尺寸不合格。Android:尝试在运行时更改TextView的宽度

在XML文件中的代码上OnCreat

<TextView 
       android:id="@+id/textScreenWidth" 
       android:layout_width="100px" 
       android:layout_height="wrap_content" 
       android:text="" 
       android:layout_gravity="center" 
       android:textColor="#ff000000" 
       android:textStyle="bold" 
       android:textSize="12dp" 

代码来改变大小

TextView t=(TextView) findViewById(R.id.textScreenWidth); 
    t.setWidth(950); 

大小不会改变

回答

2

使用此:

t.getLayoutParams().width = 950;

相关问题