2014-10-31 65 views
-3

我想重力設置爲我設計的權利,但它並沒有正常工作: (下面的代碼是一個循環內)組佈局重心向右

 LinearLayout lin = new LinearLayout(getActivity()); 
     LayoutParams lin_parms = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 
     lin_parms.gravity = Gravity.RIGHT; 
     lin.setLayoutParams(lin_parms); 
     lin.setGravity(Gravity.RIGHT); 

     LayoutParams txt_parms = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT); 
     txt_parms.gravity = Gravity.RIGHT; 


     TextView txt_view = new TextView(getActivity()); 
     txt_view.setLayoutParams(txt_parms); 
     txt_view.setTypeface(font); 
     txt_view.setText("hello"); 

     lin.addView(txt_view); 

     lay_lin_list_tractions.addView(lin); 

enter image description here

+0

你試過設置layout_gravity =「right」? – Umair 2014-10-31 11:09:20

+0

不清楚你期望什麼。請解釋預期結果 – 2014-10-31 11:09:48

回答

2

設置TextView PARAMS as WRAP_CONTENT

LayoutParams txt_parms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
+0

:so tnx,求解。 – 2014-10-31 11:10:47

+0

以及接受答案呢? :) – 2014-10-31 11:13:11

+0

你可以在7分鐘內接受答案.. :)) – 2014-10-31 11:14:14