android - addview 的位置常量是多少

标签 android

我正在尝试将 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/

相关文章:

android - Android 中的 AFSK 解调

Android 内容提供商列表

android - 如何知道用户何时将某些内容复制到android中的剪贴板?

android gradle build system - 编译项目中的路径是什么意思

android - 在网络上在线运行和模拟 Android 代码

android - 如何快速构建Android应用程序?

Android 数据绑定(bind)不起作用

java - 用户名和使用 AsyncTask 登录

android - 使用 Fitnesse 测试的 Android 中出现错误 java.lang.RuntimeException : Stub!

android - 压缩/解压缩内存中的数据