簡體   English   中英

如何在父線性布局下添加相對布局?

[英]How to add relative layout below parent linear layout?

我有線性布局的這個活動(稱為myLayout),其中有兩個按鈕。 然后,我動態地創建了一些textViews,並在一個新的相對布局(稱為relLayout)中將它們添加到彼此之下。 現在我想把這個relLayout放在myLayout 中的這兩個按鈕下面 但我不知道怎么樣,也許用myLayout.addView(relLayout, fparams); 但后來我不知道如何定義fparams ..

有任何想法嗎?

將整個布局頁面(包括myLayoutrelLayout到另一個RelativeLayout 然后你會指定relLayout位於myLayout下面,如下所示:

android:layout_below="@id/myLayout_ID"

-首先將LinearLayout設為Main Parent layout假設名為L1 ,具有Vertical orientation.

-然后創建第二個LinearLayout名稱作為L2作為child to the parent布局L1的子項 ,具有Vertical orientation

-將2 button放在此子LinearLayout L2.

-將名為Layout_weight as 1. LinearLayout L2屬性設置Layout_weight as 1.

-現在將RelativeLayout放在這個LinearLayout L2下面,然后在這里動態生成textView ....

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM