2013-03-03 133 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); 

大小不會改變

+0

什麼的TextView的父視圖? – vgarzom 2013-03-03 20:24:18

+0

你有足夠的時間知道重複你的問題是不可接受的。 [Android:嘗試在運行時更改TextView的寬度](http://stackoverflow.com/questions/15189979/android-trying-to-change-width-of-textview-at-runtime) – Sam 2013-03-03 20:44:35

回答

0

有了這個:

LinearLayout.LayoutParams lParams = new LinearLayout.LayoutParams(width, height); 
txtView.setLayoutParams(lParams); 

這假設喲你的父母佈局是LinearLayout

0

您可以設置這樣

final LayoutParams lparams = new LayoutParams(950,30); // Width , height 
    t.setLayoutParams(lparams); 
+0

實際上setWidth必須工作,但也許父親觀點的某些事情阻止了編輯。 – vgarzom 2013-03-03 20:42:29