2014-01-28 72 views
0

我想使用此代碼以編程方式更改佈局中的textView對齊方式。使用LayoutParams更改TextView的對齊方式不起作用

RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)textView1.getLayoutParams(); 
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
textView1.setLayoutParams(params); 

但是當我嘗試它RelativeLayout沒有ALIGN_PARENT_RIGHT或generaly對齊_...我應該怎麼辦?

+0

你叫'setLayoutParams'後'requestLayout'? – suitianshi

+0

嘗試textView1.setGravity(RIGHT); – Arnab

回答

0

我用:

params.AddRule (LayoutRules.AlignRight); 

相反的:

params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 

它現在...

相關問題