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

Why buttons get stuck at the top?

Hi everybody I am currently learning Android at the basic level and one question I have is that my buttons which would be at the bottom (Under TextView) got stuck at the top, how can I solve this problem? Here are my codes: <?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.hezarehee.android.storybook.ui.StoryActivity">

<ImageView
    android:id="@+id/storyImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:src="@drawable/page0"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="-71dp" />

<TextView
    android:id="@+id/storyTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="16dp"
    android:layout_marginTop="16dp"
    android:text="TextView"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/storyImageView" />

<Button
    android:id="@+id/choice1Button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:background="@android:color/white"
    android:textColor="#3A8AEC"
    android:textSize="16sp"
    tools:text="@string/page0_choice2"
    tools:layout_editor_absoluteY="476dp"
    android:layout_marginRight="8dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginLeft="8dp"
    app:layout_constraintLeft_toLeftOf="parent" />

<Button
    android:id="@+id/choice2Button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:background="@android:color/white"
    android:text="@string/page0_choice1"
    android:textColor="#3A8AEC"
    android:textSize="16sp"
    app:layout_constraintHorizontal_bias="0.497"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    tools:layout_editor_absoluteY="539dp" />

</android.support.constraint.ConstraintLayout>

and images: https://imgur.com/a/6X1rH https://imgur.com/a/p0Ss7

1 Answer

Pedro Duarte
Pedro Duarte
300 Points

I believe it's better you work with Relative Layout, position the Button where you need, with margin top, left, right or bottom, if you have pacience trainning xml for begin write your code line for line this will help for future. If nobody send the code I fix for you. Best Regards Pedro Duarte