如何设置来自代码的相对延迟下的textview的属性。
这是我的布局:

<RelativeLayout
    android:id="@+id/team_left"
    android:layout_width="wrap_content"
    android:layout_height="50dip"
    android:layout_alignParentLeft="true">
    <ImageView
        android:id="@+id/flag_left"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/img"/>
    <TextView
        android:id="@+id/country_left"
        android:textColor="@color/txt_color"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

如何从代码中设置textview的属性,如“android:layout\u torightof=@id/flag\u left”。

最佳答案

您需要对textview使用RelativeLayout.LayoutParams,然后使用addRule
例子:

RelativeLayout.LayoutParams params =
    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
                                    LayoutParams.FILL_PARENT);
params.addRule(RelativeLayout.LAYOUT_ABOVE, R.id.flag_left);
tv.setLayoutParams(params);

07-24 09:47
查看更多