对话框末尾的对话框addContentView

Dialog addContentView at the end of the dialog

在我的应用程序中有一个对话框。假设我创建了一个带有自定义视图的对话框,现在我想在第一个视图的正下方向其添加第二个视图。我用这段代码试过了:

LayoutInflater inflater = LayoutInflater.from(context);
View test = inflater.inflate(R.layout.testlayout, null, false);

dialog.addContentView(buttons, test.getLayoutParams());

但是如果我用这段代码添加第二个视图,它会出现在另一个视图的顶部。我希望第二个视图直接位于第一个视图之下。这是我的第二个视图的布局:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:clickable="true"
        android:gravity="center"
        android:text="NONE"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

我的 Dialog 的根布局是 FrameLayout,但我无法真正将其更改为其他布局。您知道如何将第二个视图设置在第一个视图下方而不是对话框顶部吗?

引用自Android docs

Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

所以你可能不应该给它 child 因为它不会变得更容易。话虽如此,为什么不将第二个视图添加到 FrameLayout 内的 ViewGroup?那是我能提供的最好的,除非我看到其他 ViewGroups。听起来你有局限性,在不了解更多的情况下很难在不知道为什么的情况下给你一个具体的答案。