truizlop / SectionedRecyclerView

An adapter to create Android RecyclerViews with sections, providing headers and footers.
806 stars 144 forks source link

Weird height problem with ImageView #14

Closed ericntd closed 8 years ago

ericntd commented 8 years ago

screen shot 2016-07-29 at 10 24 32 am

My grid_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ListItemProduct"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/holo_orange_dark"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:paddingLeft="@dimen/margin_sm"
    android:paddingRight="@dimen/margin_sm"
    android:paddingTop="0dp"
    android:layout_marginTop="0dp">

    <ImageView
        android:id="@+id/imgProduct"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="0dp"
        android:scaleType="centerInside"
        android:src="@drawable/ic_home_black_24dp"
        android:background="@android:color/holo_blue_bright"/>

    <!--<ImageView-->
        <!--android:layout_width="wrap_content"-->
        <!--android:layout_height="wrap_content"-->
        <!--android:layout_marginTop="-24dp"-->
        <!--android:id="@+id/imageView4"-->
        <!--android:src="@drawable/ic_favorite_border_black_24dp"-->
        <!--android:layout_gravity="right"/>-->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textSpecial"/>

    <TextView
        android:id="@+id/textBrand"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_weight="1"
        android:singleLine="true"
        android:maxLines="1"
        android:textSize="@dimen/font_size_sm"
        android:textStyle="bold" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textName"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textPrice"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_weight="1"
            android:singleLine="true"
            android:maxLines="1"
            android:textSize="@dimen/font_size_sm"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textSalePrice"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:textStyle="bold"
            android:layout_weight="1"
            android:gravity="end"
            android:textColor="@color/colorAccent"
            android:textSize="@dimen/font_size_sm" />

    </LinearLayout>

    <android.support.v7.widget.AppCompatRatingBar
        android:id="@+id/ratingBar2"
        style="?android:attr/ratingBarStyleSmall"
        android:progressTint="@color/colorAccent"
        android:backgroundTint="@color/colorAccent"
        android:secondaryProgressTint="@color/colorAccent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isIndicator="true"
        android:numStars="5"
        android:stepSize="0.1" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/textVariants"/>

</LinearLayout>

I printed out the image views getHeight() and getMeasuredHeight() and got 0 for both. When I changed the span count for GridLayoutManager to 1, all images have correct height. When I changed the span count to 3, only the last of the 1st row, first of 2nd row, last of 3rd row and so on have the correct image height.

ericntd commented 8 years ago

Sorry, it doesn't have do with your library, I've fixed it myself