如何将ListView放在ListView中

时间:2013-06-21 20:30:14

标签: android listview layout

所有

我有一个使用RelativeLayout的屏幕。不幸的是,需要显示的信息很大,因此为了使其可滚动,我将布局放在ScrollView中。

现在这个屏幕应该包含一个ListView。但是尝试将ListView放在xml中的Relativelayout标记中会在Eclipse中出现错误:“垂直滚动ScrollView不应包含另一个垂直滚动窗口小部件(ListView)”。

在搜索时我发现this但我使用的RelativeLayout不包含数组。

这个问题/错误还有其他解决办法吗?

谢谢。

[编辑]

稍微澄清一下。外部列表视图不基于Array或任何其他集合。它只是一个特定项目的一大组属性。现在,内部列表视图是与该特定项目相关的项目列表。此外,所有这些属性应始终在屏幕上以以下形式显示:

Property_name         Property_value

其中property_name和property_value都是TextView的。

希望这能让我更清楚自己需要拥有什么。

[/编辑]

[编辑2]

以下是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <ImageView
            android:id="@+id/product_image"
            android:contentDescription="@string/product_picture"
            android:adjustViewBounds="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_alignParentTop="true"
        />
    <View
        android:id="@+id/line1"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_image"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_price_text"
            style="@android:style/TextAppearance.Large"
        android:text="@string/product_price_text"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
    />
    <TextView
        android:id="@+id/price_with_discount"
            style="@android:style/TextAppearance.Large"
        android:layout_alignParentRight="true"
        android:layout_below="@id/line1"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
    />
    <TextView
        android:id="@+id/product_price"
            style="@android:style/TextAppearance.Large"
             android:layout_below="@id/line1"
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
    />
    <View
        android:id="@+id/line2"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_price_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_category_text"
            style="@android:style/TextAppearance.Large"
        android:text="@string/product_category_text"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line2"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
    />
    <TextView
        android:id="@+id/display_product_category"
            style="@android:style/TextAppearance.Large"
        android:layout_alignParentRight="true"
        android:layout_below="@id/line2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <View
        android:id="@+id/line3"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_category_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_code_text"
            style="@android:style/TextAppearance.Large"
        android:text="@string/product_code_text"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line3"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
    />
    <TextView
        android:id="@+id/display_product_code"
            style="@android:style/TextAppearance.Large"
        android:layout_below="@id/line3"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <View
        android:id="@+id/line4"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_code_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_availability_text"
        android:text="@string/product_availability_text"
            style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <TextView
        android:id="@+id/product_availability"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/line4"
    />
    <View
        android:id="@+id/line5"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_availability_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_dimensions_text"
        android:text="@string/product_dimensions_text"
            style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <TextView 
        android:id="@+id/product_dimensions"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/line5"
    />
    <View
        android:id="@+id/line6"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_dimensions_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_weight_text"
        android:text="@string/product_weight_text"
            style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <TextView 
        android:id="@+id/product_weight"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/line6"
    />
    <View
        android:id="@+id/line7"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_weight_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <TextView
        android:id="@+id/product_color_text"
        android:text="@string/product_color_text"
            style="@android:style/TextAppearance.Large"
        android:textStyle="bold"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/line7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <TextView 
        android:id="@+id/product_color"
            style="@android:style/TextAppearance.Large"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_below="@id/line7"
    />
    <View
        android:id="@+id/line8"
        android:layout_width="fill_parent"
        android:layout_below="@id/product_color_text"
        android:layout_height="1dp"
        android:background="#FF909090" 
    />
    <EditText
        android:id="@+id/product_quantity"
        android:text="@string/default_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/line8"
        android:layout_alignParentLeft="true"
        android:inputType="number"
    />
    <Button
        android:id="@+id/product_add_to_cart"
        android:text="@string/add_to_cart"
        android:layout_toRightOf="@id/product_quantity"
        android:layout_below="@id/line8"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
    />
    <TextView
        android:id="@+id/product_description_text"
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
        android:text="@string/product_description_text"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/product_quantity"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
    />
    <TextView
        android:id="@+id/product_description"
        android:layout_below="@id/product_description_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
    />
    <TextView
        android:id="@+id/product_related_products_text"
        android:text="@string/product_related_products_text"
        android:layout_below="@id/product_description"
            style="@android:style/TextAppearance.Large"
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
    />
    <ListView 
        android:id="@+id/product_related_products"
    >
    </ListView>
</RelativeLayout>
</ScrollView>

这是活动的xml文件。正如您所看到的,我对产品本身有很多东西(图像,名称,颜色,大小等)。所有这些都是针对1种产品,而不是产品阵列。然后在最后(底部)我想展示相关产品或同一类别的产品。

[/ EDIT2]

2 个答案:

答案 0 :(得分:4)

您不应该尝试将ListView放在listview中。它只是不会工作。 相反,我建议使用ExpandableListView,这里是tutorial

答案 1 :(得分:2)

您尝试在单个视图中显示过多信息。我建议您创建一个UI设计,将此活动分解为多个活动,每个活动都有可管理的数据块。 Application Structure是了解如何构建应用的一些想法的好地方。

相关问题