有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Android网格布局与部分文本重叠

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

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

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

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

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

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

    </RelativeLayout>

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

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

    <RelativeLayout
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content">

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

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


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

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

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

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

</LinearLayout>

共 (1) 个答案

  1. # 1 楼答案

    您缺少名称空间声明和根布局。您需要一个根布局来锚定中的所有其他内容。根据你的需要,也许一个线性布局就可以了。下面,我将所有内容包装在垂直方向的线性布局中。如果这能帮你解决任何问题,请告诉我

    <?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>