![](/img/trans.png)
[英]How to dynamically add a linear layout (as a child) to a constraint layout (parent)?
[英]How to add relative layout below parent linear layout?
我有线性布局的这个活动(称为myLayout),其中有两个按钮。 然后,我动态地创建了一些textViews,并在一个新的相对布局(称为relLayout)中将它们添加到彼此之下。 现在我想把这个relLayout放在myLayout 中的这两个按钮下面 。 但我不知道怎么样,也许用myLayout.addView(relLayout, fparams);
但后来我不知道如何定义fparams ..
有任何想法吗?
将整个布局页面(包括myLayout
和relLayout
到另一个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.