以编程方式将视图添加到LinearLayout的中间

dee*_*eeJ 5 android android-layout

我有一个有两个视图的LinearLayout

<LinearLayout>
    <TextView />
    <Textview />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

通过我的程序,我想TextView在这两个现有的TextViews' 之间添加第三个'.使用RelativeLayoutwith layout_below参数很容易.我该怎么做LinearLayout

kco*_*ock 19

LinearLayout.addView(View v, int index)

文档是从这种事情开始的好地方.

只需将索引传递到您想要放置的位置(即第二个位置为索引1).