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 属性の値を取得するにはどうすればよいですか?

4

2 に答える 2

0

代わりに、相対レイアウトの幅を取得してから、編集テキストの幅をレイアウト幅のパーセンテージに設定してみませんか。

int i = relativelayout.getWidth();
int x = //any number, depending on how wide you what your text view
textview.setWidth(i/x);
于 2013-01-09T22:27:47.453 に答える
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 は、必要に応じて変更できます。

于 2013-01-09T22:31:45.943 に答える