2011-11-26 59 views
1

我想動態地將textviews添加到linearLayout,比如textview是boo,而linearlayout是foo。addview的位置常量是什麼

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)); 

我怎麼指定的位置參數來實現它,因爲默認的一個是增加它上面。我一直在搜索文檔,但找不到位置參數的任何解釋。我得到的是這樣的:

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 

任何headup將不勝感激。

回答

2

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

+0

謝謝!順便說一下,我怎麼能知道孩子將被放置在哪裏?在我的linearLayout中,它們堆疊起來,但是relativeLayout呢?謝謝 –