2013-01-09 54 views
0

屬性我有我的佈局XML文件中下面的代碼訪問權重碼

<RelativeLayout 
    android:id="@+id/contentTextViewLayout" 
    android:layout_weight="9" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip"> 
    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
</RelativeLayout> 

如何獲取的RelativeLayout的layout_weight屬性的值,在我的代碼?

回答

0

爲什麼不相反只是獲取相對佈局的寬度,然後將edittext的寬度設置爲佈局寬度的百分比。

int i = relativelayout.getWidth(); 
int x = //any number, depending on how wide you what your text view 
textview.setWidth(i/x); 
0

你必須使用RelativeLayout.LayoutParams

嘗試以下操作:

RelativeLayout r = ((RelativeLayout)(findViewById(R.id.contentTextViewLayout))); 
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT); 
params.weight = 1.0f; 
r.setLayoutParams(params); 

params.weight = 1.0F可以改變按你的願望。