2012-08-17 105 views
0

我正在創建一個ListView,其中每個列表項都有一個LinearLayout,我想用它來動態添加多個輸入組件。我爲列表項目使用以下佈局。Android:您可以將多個孩子添加到ListView中的LinearLayout中嗎?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
> 
    ... 
    <LinearLayout 
    android:id="@+id/input_container" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    /> 
</LinearLayout> 

當我添加多個複選框到input_container我只看到第一個複選框。 LinearLayout的高度似乎是正確的(但缺少複選框的空間)。

結果看起來是這樣的:

-------------------------- 
List item 1 
[_] Option 1 








-------------------------- 
List item 2 
+0

,我發現,除去'input_container'並使用列表項的根'LinearLayout'添加多個複選框來工作。 – 2012-08-17 11:35:22

回答

1

請記住,使用正確的方向。

默認情況下,LinearLayout具有水平方向。

android:orientation="vertical" 

所以你的XML將看起來像這樣

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

    <LinearLayout 
    android:id="@+id/input_container" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation:"vertical"> 

     <!-- Your stuff here --> 

    </LinearLayout> 
</LinearLayout> 

你可以閱讀更多關於LinearLayout及其價值取向的位置:Android Developer: LinearLayout

+0

謝謝!我已經擔心我忽略了一些微不足道的東西。 – 2012-08-27 15:58:32

+0

不客氣。我們都忽略了一些微不足道的東西:-) – 2012-08-28 07:28:12

相關問題