Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

Oscar Acevedo
Oscar Acevedo
8,240 Points

Can't drag elements on the design tab

Hello everyone!

So after creating my project with the empty activity and changing the layout to RelativeLayout, no matter what, the TextView is always on the top left corner of the screen, I can drag it but it goes back to the corner. This is how the xml looks.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Did you know?" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</RelativeLayout>

Thank you!

1 Answer

Hi Oscar. I'm not sure what layout you have in mind (i.e views side-by-side, under one another...) but with a RelativeLayout, you are supposed to tell your layout how the views should be positioned relatively to one another.

So you should give each of your views an id, then attributes explaining what its relative position to the parent or the sibling(s) is. Have a look at the official documentation for help.

Happy coding :)

Edit: Otherwise, just click on the magnet icon in the Layout Editor) so that it's not crossed out to activate Autoconnect and the relative layout attributes will be added automatically for you as you place your views around the layout.