Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Android Lists and Adapters (2015) Lists with RecyclerViews Using a Layout Manager

Oziel Perez
Oziel Perez
61,321 Points

Glitch while rendering the RecyclerView list items

Everything is working fine in the weather app. Only thing is that, after I press the "Hour" button, the list shows up but instead of the icon and summary label being laid out evenly between the time and temperature labels, both the icon and summary label overlap on top of each other. The problem fixes itself if I scroll down; the views return to normal and when I scroll back up, those "glitched" items are back to normal. I'm using an emulator running the old Android v4.1, so what could have gone wrong?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                tools:background="#FFAA00"
                android:paddingTop="8dp"
                android:paddingBottom="8dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

    <TextView
        android:id="@+id/timeLabel"
        tools:text="12 PM"
        android:textSize="24sp"
        android:textColor="#FFF"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_width="80dp"
        android:layout_height="wrap_content"/>

    <ImageView
        android:id="@id/iconImageView"
        tools:src="@drawable/partly_cloudy"
        android:contentDescription="weather icon"
        android:layout_toRightOf="@id/timeLabel"
        android:layout_toEndOf="@id/timeLabel"
        android:layout_centerInParent="true"
        android:layout_centerHorizontal="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@id/summary"
        android:textColor="#FFF"
        tools:text="Partly Cloudy"
        android:layout_centerHorizontal="false"
        android:layout_toRightOf="@id/iconImageView"
        android:layout_toEndOf="@id/iconImageView"
        android:layout_centerVertical="true"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@id/temperatureLabel"
        tools:text="100"
        android:textColor="#FFF"
        android:textSize="24sp"
        android:layout_centerVertical="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</RelativeLayout>

1 Answer

Oziel Perez
Oziel Perez
61,321 Points

I figured it out. The one line that says android:layout_centerInParent="true" in the ImageView is what was causing the problem. I erased it and it went away.