[英]Android - Grid layout overlapping some of the text
因此,我正在创建此应用程序,该应用程序将在网格中显示产品,例如,在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>
您缺少名称空间声明以及根布局。 您需要一个根布局来锚定其他所有内容。根据您的需要,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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.