gpt4 book ai didi

android - addview 的位置常量是多少

转载 作者:行者123 更新时间:2023-11-29 22:16:43 30 4
gpt4 key购买 nike

我正在尝试将 TextView 动态添加到线性布局,假设 TextView 是 boo,线性布局是 foo。

TextView boo = new TextView(this)
LinearLayout foo = findViewByID(R.id.examplelayout)

我正在尝试将 TextView 添加到布局中现有 TextView 的正下方。当我添加它时

foo.addView(boo, int position new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));

我怎么指定position参数来实现呢,因为上面默认是加的。我一直在搜索文档,但找不到位置参数的任何解释。我得到的只是这个:

  public void addView (View child, int index, ViewGroup.LayoutParams params) 
Since: API Level 1
Adds a child view with the specified layout parameters.

Parameters
child the child view to add
index the position at which to add the child
params the layout parameters to set on the child

如有任何提示,我们将不胜感激。

最佳答案

您可以使用方法foo.getChildCount()

关于android - addview 的位置常量是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8280002/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com