0

所以我正在创建这个应用程序,它将在网格中显示产品,例如在 nexus 7 纵向视图中,每行 2 个,而在横向模式下,将连续 4 个。每个产品都有一个想象,然后它下面的几个文本视图显示一些信息。

然而,显示免费送货和特价数量的最后两个文本视图似乎与下面的下一张图片重叠。谁能帮我指出我哪里出错了。布局如下:

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

    <RelativeLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/product_grid_lister_image_background"
        android:padding="1dp" >

        <ProgressBar
            android:id="@+id/image_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:indeterminateDrawable="@drawable/progress_blue" />

        <ImageView
            android:id="@+id/product_grid_lister_image"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_margin="10dp"
            android:scaleType="center"/>

    </RelativeLayout>

    <RatingBar
        android:id="@+id/product_grid_lister_rating_bar"
        style="@style/GoldRatingBar.Large"
        android:layout_width="wrap_content"
        android:layout_height="18dp"
        android:layout_marginTop="5dp"
        android:numStars="5" />

    <TextView
        android:id="@+id/product_grid_lister_product_name_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:lines="2"
        android:includeFontPadding="false"
        android:textColor="@color/black"
        android:textSize="@dimen/text_dp_14pt" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/product_grid_lister_price_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:includeFontPadding="false"
            android:textColor="@color/black"
            android:textSize="@dimen/text_dp_20pt" />

        <TextView
            android:id="@+id/product_grid_lister_was_price_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_price_text"
            android:includeFontPadding="false"
            android:textColor="@color/grey"
            android:textSize="@dimen/text_dp_14pt" />


        <TextView
            android:id="@+id/product_grid_lister_offer_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_was_price_text"
            android:includeFontPadding="false"
            android:textColor="@color/red"
            android:textSize="@dimen/text_dp_14pt" />

        <TextView
            android:id="@+id/product_grid_lister_special_offer_text"
            style="@style/plp_special_offer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_offer_text"
            android:includeFontPadding="false"
            android:text="@string/plp_special_offer" />

        <TextView
            android:id="@+id/product_grid_lister_delivery_offer_text"
            style="@style/plp_special_offer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_special_offer_text"
            android:includeFontPadding="false"
            android:text="@string/plp_delivery_offer" />

        <CheckBox
            android:id="@+id/product_grid_lister_star_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:paddingTop="6dp"
            android:paddingBottom="6dp"
            android:paddingLeft="6dp"
            android:button="@drawable/product_grid_star_checkbox"
            android:focusable="false" />
    </RelativeLayout>

</LinearLayout>
4

1 回答 1

0

您缺少命名空间声明以及根布局。您需要一个根布局来锚定其他所有内容。根据您的需要,也许 LinearLayout 可以解决问题。下面我将所有内容都包装在垂直方向的线性布局中。让我知道这是否能为您解决任何问题。

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

    <RelativeLayout
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/product_grid_lister_image_background"
        android:padding="1dp" >

        <ProgressBar
            android:id="@+id/image_loading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:indeterminateDrawable="@drawable/progress_blue" />

        <ImageView
            android:id="@+id/product_grid_lister_image"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_margin="10dp"
            android:scaleType="center" />
    </RelativeLayout>

    <RatingBar
        android:id="@+id/product_grid_lister_rating_bar"
        style="@style/GoldRatingBar.Large"
        android:layout_width="wrap_content"
        android:layout_height="18dp"
        android:layout_marginTop="5dp"
        android:numStars="5" />

    <TextView
        android:id="@+id/product_grid_lister_product_name_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:includeFontPadding="false"
        android:lines="2"
        android:textColor="@color/black"
        android:textSize="@dimen/text_dp_14pt" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/product_grid_lister_price_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:includeFontPadding="false"
            android:textColor="@color/black"
            android:textSize="@dimen/text_dp_20pt" />

        <TextView
            android:id="@+id/product_grid_lister_was_price_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_price_text"
            android:includeFontPadding="false"
            android:textColor="@color/grey"
            android:textSize="@dimen/text_dp_14pt" />

        <TextView
            android:id="@+id/product_grid_lister_offer_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_was_price_text"
            android:includeFontPadding="false"
            android:textColor="@color/red"
            android:textSize="@dimen/text_dp_14pt" />

        <TextView
            android:id="@+id/product_grid_lister_special_offer_text"
            style="@style/plp_special_offer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_offer_text"
            android:includeFontPadding="false"
            android:text="@string/plp_special_offer" />

        <TextView
            android:id="@+id/product_grid_lister_delivery_offer_text"
            style="@style/plp_special_offer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/product_grid_lister_special_offer_text"
            android:includeFontPadding="false"
            android:text="@string/plp_delivery_offer" />

        <CheckBox
            android:id="@+id/product_grid_lister_star_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:button="@drawable/product_grid_star_checkbox"
            android:focusable="false"
            android:paddingBottom="6dp"
            android:paddingLeft="6dp"
            android:paddingTop="6dp" />
    </RelativeLayout>

</LinearLayout>
于 2013-11-04T14:26:09.757 回答