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) Using Parcelable Data Updating the Daily Forecast UI

Jarvis Chandler
Jarvis Chandler
7,619 Points

Weather app working fine but temperature padding is off?

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="16dp" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="16dp" tools:context="teamtreehouse.com.stormy.ui.DailyForecastActivity" android:background="@drawable/bg_gradient" android:gravity="center">

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@android:id/list"
    android:layout_alignParentTop="false"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_below="@+id/thisWeekLabel"
    android:layout_above="@+id/locationLabel"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:divider="@null"
    android:dividerHeight="0dp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/no_daily_forecast_data"
    android:id="@android:id/empty"
    android:layout_centerVertical="true"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffffff"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="This Week&apos;s Weather"
    android:id="@+id/thisWeekLabel"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffff"
    android:textSize="30sp"
    android:layout_marginTop="16dp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Conway, AR"
    android:id="@+id/locationLabel"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:textColor="#ffffff"
    android:textSize="18sp"
    android:layout_marginBottom="10dp"/>

</RelativeLayout>

1 Answer

Stephen Wall
PLUS
Stephen Wall
Courses Plus Student 27,294 Points

I believe what you are looking for is located in the daily_list_item.xml file. It's in this layout file that the padding is applied to the ImageViews that live within the cells. If you look at the second ImageView below, the padding is applied to the left side. You may have missed something in here. Layouts can be tedious. Also you may just need to set the alignment of the temperature TextView to the circleImageView that holds the temperature. If you look to the last item in the code below you can see that it is set to align to all 4 sides of the circle. Then the gravity is set to center, which places it within the center evenly. Let me know if this helps.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingLeft="64dp"
                android:paddingRight="32dp"
                android:paddingTop="4dp"
                android:paddingBottom="4dp"
                tools:background="#ffaa00">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/circleImageView"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:src="@mipmap/bg_temperature"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/iconImageView"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/circleImageView"
        android:layout_toEndOf="@+id/circleImageView"
        android:paddingLeft="10dp"
        android:src="@mipmap/clear_day"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/dayNameLabel"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/iconImageView"
        android:layout_toEndOf="@+id/iconImageView"
        android:paddingLeft="10dp"
        android:textColor="#ffffffff"
        android:textSize="20sp"
        tools:text="Wednesday"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/temperatureLabel"
        android:layout_alignTop="@+id/circleImageView"
        android:layout_alignBottom="@+id/circleImageView"
        android:layout_alignLeft="@+id/circleImageView"
        android:layout_alignRight="@+id/circleImageView"
        android:gravity="center"
        android:textColor="#f25019"
        tools:text="100"/>
</RelativeLayout>