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 Build a Simple Android App Creating the Screen Layout Adding a Button

what did i do wrong?

every time i run the program all the buttons shift to the top left corner. No i didn't set them there it just does it.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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="com.example.slohr5891.androidassignment1.FunFacts">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:lineSpacingExtra="8sp"
        android:text="Did you know..."
        android:textSize="24sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.111"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.058" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/factTextView"
        android:lineSpacingExtra="8sp"
        android:text="ants stretch when they wake up in the morning?"
        android:textSize="24sp"
        tools:layout_editor_absoluteX="25dp"
        tools:layout_editor_absoluteY="88dp" />

    <Button
        android:id="@+id/showFactButton"
        android:layout_width="368dp"
        android:layout_height="wrap_content"
        android:text="Show another fun fact"

        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="410dp" />

</android.support.constraint.ConstraintLayout>

1 Answer

It looks like the challenge you posted this again is wanting you to copy and paste the TextView element and change 'TextView' to 'Button' - resulting in:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

</RelativeLayout>