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

Was this supposed to be obvious? ... Re: dimens.xml to list_item.xml syncing challenge

http://teamtreehouse.com/library/adding-margins-to-listviews

Challenge Task 3 of 4

Now switch to the file list_item.xml. Add left and right margins to the RelativeLayout element using the horizontal dimension you just added.

Don't you just hate when you come in to the middle of a movie and don't know what's going on?

Challenge parts 1 & 2 I had trouble with also.

I searched the forum and found this thread (totally unrelated to this challenge, but I'm getting really really good at using the rather mediocre search capabilities of the treehouse forum) which had some dimens.xml code: https://teamtreehouse.com/forum/stage-2-challenge-1-3

<resources>
    <!-- Default screen margins, per the Android Design guidelines. -->
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
</resources>

However, that code doesn't fit this challenge (but it's closer than anything else I found outside the video).

If you drop the "activity_" from each line (and apply the stupid "dp" settings required by the challenge) you get:

//dimens.xml file code:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <dimen name="horizontal_margin">10dp</dimen>
    <dimen name="vertical_margin">6dp</dimen>
</resources>

So the above code got me past challenges 1 & 2,

to right now (challenge 3 of 4), where I'm stuck again.

I'm not stupid... but what exactly am I supposed to add to the provided code:

//list_item.xml

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/item_background_color" >

I was thinking it might be:

android:marginLeft="horizontal_margin"
android:marginRight="horizontal_margin"

But, alas, no..didn't pass.

Okay let's try:

android:layout_marginLeft="horizontal_margin"
android:layout_marginRight="horizontal_margin"

Then (finally) it comes up with a useful (if cryptic) debugging message saying something about using "@dimen".

Hmmm...so maybe:

android:layout_marginLeft="@dimenhorizontal_margin"
android:layout_marginRight="@dimenhorizontal_margin"

AAArrrggg...another error! Man, I'm so close.

I can feel the answer engine is taunting me!!!!

I don't like to be taunted <grits teeth> !!!

android:layout_marginLeft="@dimen/horizontal_margin"
android:layout_marginRight="@dimen/horizontal_margin"
android:layout_marginTop="@dimen/vertical_margin"

..and after all that I get a measly 6 points!

Oh well...defeating this challenge got me halfway through the "Customizing a ListView for the Inbox" section of "Implementing Designs for Android".

Onward, three more sections..

Ken Alger
Ken Alger
Treehouse Teacher

Sorry you had issues with these challenges, but I thought they were rather straight forward given the time spent in the videos and the project discussing the syntax for android layouts and creating standardized, reusable values.

Happy coding,

Ken

Try this it worked for me...

android:layout_marginLeft="@dimen/horizontal_margin" android:layout_marginRight="@dimen/horizontal_margin"