Android 更改代码中相对延迟的布局重量

Android 更改代码中相对延迟的布局重量,android,Android,我的xml文件中有以下一段布局。在我的xml中还有其他类似的RelativeLayouts <RelativeLayout android:id="@+id/contentTextViewLayout" android:layout_weight="0.9" android:layout_width="fill_parent" android:layout_height="0dip"> <TextView andr

我的xml文件中有以下一段布局。在我的xml中还有其他类似的
RelativeLayouts

    <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>


我想在我的代码中更改
RelativeLayout
layout\u weight
参数。我该怎么做

请参见此处对第一个问题的评论:

将您的relativelayout替换为textview

编辑,将其全部拼出来:

首先为您的外部管路布局充气:

    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));

请参见对第一个问题的评论:

将您的relativelayout替换为textview

编辑,将其全部拼出来:

首先为您的外部管路布局充气:

    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));

重复:您共享的示例通过代码显示了所有组件。在我的例子中,xml中已经定义了组件布局。我只需要根据某些条件访问和更改代码中的一个参数(布局权重)。
RelativeLayout
没有
android:layout\u weight
属性。这是针对
LinearLayout
@commonware的,但是
LinearLayout
内部的
RelativeLayout
可以被赋予
layout\u wieght
,我想这就是这里的情况。@jcw:啊,好的,我很抱歉。重复:您共享的示例中,所有组件都是通过代码获得的。在我的例子中,xml中已经定义了组件布局。我只需要根据某些条件访问和更改代码中的一个参数(布局权重)。
RelativeLayout
没有
android:layout\u weight
属性。这是针对
LinearLayout
@commonware的,但是
LinearLayout
内部的
RelativeLayout
可以被赋予
layout\u wieght
,我想这就是这里的情况。@jcw:啊,好的,我很抱歉。这很有帮助。我将此标记为一个答案,但是我在查看设置参数的效果时遇到问题。我也会提出一个新问题。这很有帮助。我将此标记为一个答案,但是我在查看设置参数的效果时遇到问题。我将提出一个同样的新问题。