简体   繁体   English

android recyclerview gridview项目无法正确显示

[英]android recyclerview gridview item not showing properly

I am using recyclerview gridview to show product. 我正在使用recyclerview gridview来显示产品。 But its showing like this this is the view 但是它的显示是这样

my xml view code is 我的xml查看代码是

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical">

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="@dimen/cover_height"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    card_view:cardUseCompatPadding="true"
    android:elevation="7dp">

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


        <com.makeramen.roundedimageview.RoundedImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/thumbnail"
            android:src="@drawable/placeholder_image"
            android:scaleType="fitXY"
            app:riv_oval="false"
            app:riv_corner_radius_top_left="6dp"
            app:riv_corner_radius_top_right="6dp"
            android:layout_height="@dimen/cover_height"
            android:layout_width="match_parent" />

        <pseudozero.smalam.com.finwallet.utils.TextViewPlus
            android:id="@+id/tvProductTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/thumbnail"
            android:textColor="@color/colorBlack"
            android:textSize="15dp"
            android:text="Wrist Watch"
            android:padding="5dp"
            app:customFont="fonts/Proxima_Nova_Bold.otf"/>


        <pseudozero.smalam.com.finwallet.utils.TextViewPlus
            android:id="@+id/tvProductVendor"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvProductTitle"
            android:textSize="13dp"
            android:paddingLeft="5dp"
            android:paddingBottom="5dp"
            android:text="Rolex"
            app:customFont="fonts/Proxima_Nova_Reguler.otf"/>

        <pseudozero.smalam.com.finwallet.utils.TextViewPlus
            android:id="@+id/tvPriceTag"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="500 BDT"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:textColor="@color/colorWhite"
            android:textSize="13dp"
            android:padding="10dp"
            android:background="@drawable/price_tag_back_n"
            app:customFont="fonts/Proxima_Nova_Bold.otf"/>

    </RelativeLayout>

</android.support.v7.widget.CardView>

I am using a card view inside linearlayout. 我在linearlayout中使用卡片视图。 But I am getting this I am loading all data from server. 但是我正在从服务器加载所有数据。 Only the second item is going up. 仅第二项上升。 I want that all items will be decorated. 我希望所有物品都将被装饰。

  1. Use fixed height of CardView and RoundedImageView 使用CardViewRoundedImageView固定高度
  2. Use attribute android:scaleType="centerCrop" instead of android:scaleType="fitXY" to RoundedImageView . 使用属性android:scaleType="centerCrop"而不是android:scaleType="fitXY"RoundedImageView

Hope this will help~ 希望这会有所帮助〜

RelativeLayout Height should be wrap_content RelativeLayout Height应该是wrap_content

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

to

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

And in your code you do not close parent LinearLayout. 并且在您的代码中,您不会关闭父级LinearLayout。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM