我有一个带有线性布局的 Activity (称为 myLayout),其中有两个按钮。然后,我动态地创建了 textView 数组,并将它们添加到一个新的相对布局(称为 relLayout)中。现在我想将此 relLayout 放在 myLayout 中的这两个按钮下方。但我不知道如何,也许使用 myLayout.addView(relLayout, fparams);
但我不知道如何定义 fparams..
有什么想法吗?
最佳答案
- 首先设一个 LinearLayout
作为 Main Parent 布局
假设命名为 L1,其中 垂直方向。
- 然后创建第二个 LinearLayout
名称为 L2 作为父级
布局的 L1,垂直方向
-将 2 个按钮
放置在此子 LinearLayout L2 中。
- 将名为 Layout_weight 的
LinearLayout
L2 属性设置为 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>
关于java - 如何在父线性布局下方添加相对布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12543085/