addview的位置常量是多少?

时间:2011-11-26 16:53:31

标签: android

我正在尝试动态地将textviews添加到linearLayout,比如textview是boo,而linearlayout是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  

任何单挑都会受到赞赏。

1 个答案:

答案 0 :(得分:2)

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