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 (2014) Creating the Screen Layout Setting Padding

stage 2 challenge 1

Let's change the default padding of our screen layout from 16dp to 32dp. Make sure you make the change in the file dimens.xml!

activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:background="#fff092b0" >

  <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Treehouse loves me!"
    android:textSize="72sp"
    android:textColor="@android:color/white"/>

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

3 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

Hi

The challenge is asking you to change the size of the padding from 16 dp (density pixels) to 32 dp. The dimensions are already specified inside the dimens.xml file you have posted (You only need to alter values in the dimens.xml file ignore the other file completely for the moment) .The tags inside this file don't require any alterations only the values between the opening and closing tags.

Hopefully this helps you along without me simply pasting the correct code, I think it's always more rewarding to get to the correct answer yourself but please post back here if you are still struggling and I can assist further.

Thanks Daniel

thanks but its not working where exactly should l change .do l change from this <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>

or android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin

wooooooooow it worked .....thank you very much

Daniel Hartin
Daniel Hartin
18,106 Points

No problem, glad you cracked it!

thanks but its not working where exactly should l change .do l change from this <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen>

or android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"

Daniel Hartin
Daniel Hartin
18,106 Points

Hi

You are looking at the wrong file go into the dimens.xml file (You have posted it above, it is the file with only 2 lines of code - shown below)

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

You need to alter the values in these lines of code from 16dp to 32dp like the below

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

The reason we put all the dimensions into a separate file is so we can make alterations to the entire app without having to alter each padding value independently it can be more confusing at first but keep with it, it becomes second nature.

Hope this helps but let me know if you are still having trouble

Thanks Daniel

All you have to do is go to change the 16dp to 32dp. thats it.