0

我有这个带有线性布局的活动(称为 myLayout),其中有两个按钮。然后,我动态地创建了一个 textView 数组,并将它们添加到一个新的相对布局(称为 relLayout)中。现在我想把这个 relLayout放在 myLayout 中这两个按钮的下面。但我不知道如何,也许有myLayout.addView(relLayout, fparams);但我不知道如何定义 fparams ..

有任何想法吗?

4

2 回答 2

1

myLayout将包括and在内的整个布局页面包装relLayout到另一个RelativeLayout. 然后你会像这样指定到relLayout下面的位置myLayout

android:layout_below="@id/myLayout_ID"
于 2012-09-22T10:56:19.373 回答
1

-首先让 aLinearLayout作为Main Parent layout名为L1的假设,其中Vertical orientation.

-然后创建第二个LinearLayout名称作为L2作为child to the parent布局L1,与Vertical orientation

-将 2button放在这个孩子身上LinearLayout L2.

-设置这个LinearLayoutL2 属性命名Layout_weight as 1.

-现在把RelativeLayout这个LinearLayout L2放在下面,然后动态生成textViewhere....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" android:layout_weight="1">

        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />


        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />

    </LinearLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" >
    </RelativeLayout>

</LinearLayout>
于 2012-09-22T10:57:51.597 回答