2011-06-11 103 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