1

xmlファイルに次のレイアウトがあります。RelativeLayouts私のxmlには他にも同様のものがあります

    <RelativeLayout
    android:id="@+id/contentTextViewLayout"
    android:layout_weight="0.9"
    android:layout_width="fill_parent"
    android:layout_height="0dip">
    <TextView
        android:id="@+id/textViewStory1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:lineSpacingMultiplier="1.2"
        android:textColor="#000000"
        android:background="@drawable/book"/>
</RelativeLayout>

コード内ののlayout_weightパラメータを変更したい。RelativeLayoutどうやってやるの?

4

1 に答える 1

1

ここで最初の質問のコメントを参照してください:

TextViewのレイアウトの重みをプログラムで設定します

textviewの代わりにrelativelayoutを使用してください。

編集して、すべてを詳しく説明します。

まず、外側のLinearLayoutを膨らませます。

    LayoutInflater inflater = LayoutInflater.from(context);
    LinearLayout ll = (LinearLayout)
        inflater.inflate(R.layout.some_linear_layout, null);
    // now get a reference to your relativelayout inside it
    RelativeLayout yourRL = (RelativeLayout)
        ll.findViewById(that_relative_layout);

    // parameters are width, height, weight
    yourRL.setLayoutParams(new 
        LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 0, 1f));
于 2013-01-25T22:47:15.170 に答える