2011-06-11 32 views
0

我試圖創建下面雖然機管局屏幕布局:在它機器人,如何將滾動視圖在屏幕的中間:

  1. 一個符合一些的TextView
  2. 一種渦查看用戶操作將添加或刪除的位置從
  3. 查看
  4. 按鈕行。

我對1.或3.沒有問題但是2.給我帶來麻煩。我的方案是:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mainX" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/labels" 
    android:layout_weight="1"> 
    <!--Some text view of various sizes --> 
    </LinearLayout> 
    <ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/dataScroll"> 
    <LinearLayout 
     android:id="@+id/dataShow" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </LinearLayout> 
    </ScrollView> 
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/buttons" 
    android:layout_weight="1"> 
    <!--some buttons--> 
    </LinearLayout> 
</LinearLayout> 

當運行該程序時,按鈕行是在屏幕的中部和當我添加元素來在屏幕上(使用關於dataShow佈局addView),弗里斯特一個加入沒有問題,但之後我不知道發生了什麼。

謝謝

回答

0

我不完全確定你在做什麼。

看來你想動態添加項目到dataShow佈局。您應該爲您的dataShow佈局使用ListView(垂直滾動)或Gallery(水平滾動),而不是使用包含LinearLayout的ScrollView。這將提供滾動功能,並允許您將項目動態添加到列表/圖庫中。

+0

您已經正確理解我(至少部分),但是,我找不到如何將視圖添加到ListView。我只發現使用addView引發異常。 – Yotam 2011-06-11 21:00:01

+0

我玩弄了我所能找到的ListView,它只支持String。雖然我需要放置一些自定義視圖。這是真的嗎? – Yotam 2011-06-11 21:17:33

+0

爲了獲得自定義視圖,您需要使用自己的自定義適配器並重寫getView()方法。請務必使用持有者模式並重新使用convertView。我只是做了快速谷歌搜索,發現這個鏈接http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/。我沒有閱讀這篇文章,但我看了一下代碼,看起來是正確的。 – Noel 2011-06-11 23:42:22

相關問題