Android:我应该使用ListView吗? (case:列出部分未知结构的元素)

时间:2011-12-30 13:10:46

标签: android listview android-layout android-listview convertview

关于列表的假设(更新):

  • 包含 10个列表元素 (列表元素由下面的xml布局定义)。< / S>
  • 每个元素的高度都是未知的,因为list元素包含LinearLayout,最多可包含 20个子视图 (请参阅下面的xml)。

列表元素的XML布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation:"horizontal">

    <!--
        This LinearLayout is going to contain one or more 
        Views which will be added progammatically on runtime.
        The number of children views added to it depend on the 
        data to be displayed, and the only assumption that can 
        be made is that there's will be no more than 20 child 
        views for one particular instance of this LinearLayout.
    -->
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginRight="25dp"/>

    <ImageButton
        android:layout_width="25dip"
        android:layout_height="25dip"
        android:layout_gravity="center|top"
        android:layout_marginLeft="-25dp"/>
</LinearLayout>

问题:

  • ListView用于具有此类自由的布局是否有意义 在其结构(如上面的那个)中,仍然能够利用这个 convertView传入ListView#getView(...)
  • 作为替代方案,将所有列表元素放在外部是不对的 LinearLayout并将其置于ScrollView之内?通过这样做,我不会得到 缓存ListView的能力,但也许它不会那么沉重 关于清单的假设? (见上)。 (有关如何使这种替代外观和感觉像ListView的任何指示?我正在考虑应用标准颜色和选择器等。)

1 个答案:

答案 0 :(得分:1)

如果你知道你的10个元素中的一些将是相同的,你可以使用

getItemViewType(int position)

确保convertView与您的项目类型convertView

匹配