Bummer! You must be logged in to access this page.

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

Tate Pultro
Tate Pultro
11,765 Points

My textView always snaps to the top of the page instead of below the imageView (where I place it).

Whenever I drop in my textView, it always aligns to the top of the page in the layout instead of to the bottom of the imageView (where I place it). What am I doing wrong?

Here's my XML:

<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" tools:context="com.mtatepultro.interactivestory.ui.StoryActivity">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/imageView"
    android:src="@drawable/page0"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Text"
    android:id="@+id/textView"
    android:layout_below="@+id/imageView"
    android:layout_alignLeft="@+id/imageView"
    android:layout_alignStart="@+id/imageView" />

</RelativeLayout>

Thanks.

Have you tried zooming in to give yourself a finer control and just move it around until you get the option to place below the imageview.

Looking at your XML though, it says it is below the imageView, which should be correct?

1 Answer

You need to change the following in the TextView.

android:layout_below="@+id/imageView to android:layout_above="@+id/imageView.

Sometimes, the Graphical Layout editor does not always give you precise control. It helps a tonne to know how to edit the XML as it gives you much more control of the layout rather than the graphical editor. TIP: If you wish to preview your layout while editing the XML, you can click on Preview in the right-hand toolbar on the side.

Hope it helps! xD