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 trialFrank Fox
978 PointsCode Challenge - Handling a Lack of Data - Step 2
So, I've tried this a variety of ways, but while I get the "bummer!" error, the preview doesn't give any details on why I'm wrong; I get a blank white page. I've cleared my browser cache, so that's not causing the lack of Preview mode.
On Step 2, the requirement is as follows: Now add the android:layout_width and android:layout_height attributes and set both equal to the value that shrinks the Button around its content (the text on the Button, in this case).
Here is my XML 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" >
<Button>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
</Button>
</RelativeLayout>
So, I feel like wrap_content is correct based on what that does to the element. That being said, I've tried using match_parent for both, or even one as wrap_content and one as match_parent, swapped those, and still get the "bummer" error. I feel like the assignment is only to setup the layouts, so I'm lost here (and totally because of the lack of the Preview window). Any insight on this?
2 Answers
Liam Peters
8,792 PointsHi Frank,
there isn't anything wrong with your wrap_content. There is however, something wrong with where you are defining them.
Something between the <Button>
tags is a child element of the button (just like when you put the button between the two <LinearLayout>
tags to say it's inside the linear layout). To define attributes about the button, we must put this before the closing >
of the opening button tag. So something like below:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
</Button>
Hope that helps!
Frank Fox
978 PointsAh! Thanks, Liam. I totally didn't grasp the concept of wrapping it into the tag itself. Thanks again!