你能给我一个非常简单的例子,在给定的位置以编程方式将子视图添加到RelativeLayout
?如何以编程方式向RelativeLayout添加视图?
例如,要体现以下XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="107dp"
android:layout_marginTop="103dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
我不知道如何创建一个合适的RelativeLayout.LayoutParams
实例。
对不起,同样的问题:你在哪里学习了没有Context作为第一个参数的'RelativeLayout.LayoutParams'构造函数? –
@SuzanCioc请参阅上面的编辑 – JRaymond
啊,对不起,认为宽度和高度应该是确切的值。 –