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 an Interactive Story App (Retired) User Input Using EditText for Text Input

Hassam Uddin
Hassam Uddin
8,204 Points

alignParentStart deprecated?

My image looks different from the one being shown in Ben's view, mine has more white-space even though we are using the same model for our emulator. The only difference in the code is an element that he uses called alignParentStart. When adding this Android Studio throws an error stating that the term isn't recognized.

I'm using the latest android studio with 4.2 unlike the one we're supposed to use. I can't find any change logs, and there doesn't seem to be a replacement for it. What should I use to replace this term, and if that isn't the problem, what else could be?

Ben Deitch
Ben Deitch
Treehouse Teacher

Hmm tough to be sure without the code. Could you post the code? Otherwise, do you have both android:layout_alignParentStart="true" and android:layout_alignParentLeft="true" specified?

Hassam Uddin
Hassam Uddin
8,204 Points

Sorry for the late reply, here's the code:

<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=".MainActivity">

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:text="Name"
    android:ems="10"
    android:id="@+id/editText"
    android:layout_alignParentLeft="true"
    android:contentDescription="Signals from Mars" />

<ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/titleImageView"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:src="@drawable/main_title"
    android:scaleType="fitXY"
    android:adjustViewBounds="true"
    android:layout_alignParentStart="true" />

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="START OUR ADVENTURE"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true" />

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:id="@+id/nameEditText"
    android:layout_above="@+id/button"
    android:layout_alignParentLeft="true"
    android:hint="Enter your name to begin"
    android:maxLength="30" />

</RelativeLayout>

Ben Deitch
Ben Deitch
Treehouse Teacher

That looks ok to me. What's the error exactly? If it's this: No resource found that matches the given name: attr 'android:layout_alignParentStart'. - then the compileSdkVersion/targetSdkVersion (in build.gradle) might be too low. Also, for this app, alignParentStart and alignParentLeft are doing the same thing; as long as you have one of those you should be ok. AlignParentStart really shines when a layout can be both right-to-left (perhaps to support Arabic) and left-to-right.

Hassam Uddin
Hassam Uddin
8,204 Points

That's the exact error, How do I upgrade my sdk? Its at the current 6.0.

Ben Deitch
Ben Deitch
Treehouse Teacher

You should be able to fix this by changing the compileSdkVersion, targetSdkVersion, and buildToolsVersion to be something more current (>19). You can see how Ben J does it here.