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 trialSara Mørk
Full Stack JavaScript Techdegree Student 2,838 PointsProject layout is fine under the Design tab, but is "squished" together in the AVD. How can I fix this?
I'm following Beginning Android Development, and am experiencing difficulties with running the project on the Android Virtual Device.
Everything seems fine under the Design tab, but when I run the application in a virtual device, the layout looks very very.. wrong.. :S
The best way I can describe how it looks is to make a tiny comparison to CSS - it is as though every object in the layout has position: absolute; - because all the objects on the layout are living on the topmost corner of the AVD's screen, and overlapping one another. This isn't how it looks like under the design tab, which is why I am really confused.
I'm not sure I've missed a step, or if I need to take extra steps to fix this??
I've included a screenshot of what's wrong.
Hope to hear from you guys soon!
- Sara
2 Answers
Matthias Margot
7,236 PointsTheres a bunch of reasons why this could happen.
You're not using a RealativeLayout as the parent Layout.
Your Views weren't actually aligned correctly when you placed them (they need to touch the edges and they need to be green then you release your view, in case your using the drag and drop editor).
Another reason could be that you haven't defined the ID's of the Views before your dragged them into the right place or you haven't defined them at all (If you have defined them check in the XML file if the name of the View is the same as in the editor and first of all check if it has a name at all obviously).
You have placed your views using hard coded non-relative units, like say, 48px instead of 48dp. If you did that your layout will only appear the way you want it to on the screen size you were using in the editor and appear relatively out of place on every other screen size.
I'm sorry that i can't tell you the exact reason for this happening. You just didn't provide enough information to me. I would be glad to reply to you as soon as i can if you were to copy in your xml code in here. I would 100% be able to tell you what's wrong if i could see the xml file.
hope i could help
Matthias :)
Seth Kroger
56,413 PointsAndroid Studio is one of those tools that keeps changing constantly. This includes the templates you get when you create a new Activity, etc. Since the course was released the default parent layout was changed from a RelativeLayout to a ConstraintLayout. If you you go to the XML and change android.support.constraint.ConstraintLayout
to RelativeLayout
at both the top and bottom of the file that should fix things.
Sara Mørk
Full Stack JavaScript Techdegree Student 2,838 PointsSara Mørk
Full Stack JavaScript Techdegree Student 2,838 PointsThank you so much for your response!
I've taken a look at my XML, and it looks like the layout is "Constraint"? Not sure I am looking in the correct place though (and not quite sure how to solve the issue :S)
Matthias Margot
7,236 PointsMatthias Margot
7,236 Points@Sara Mørk Couple of things wrong with your code.
(I'd suggest you delete your current Layout file and just create a new one with the RelativeLayout, still read this tho if you wanna know how to set it up correctly)
Now a relativeLayout works like this: Every view's position is defined relative to either other views or it's parent. You can either code this yourself or just fiddle around with the drag and drop layout editor. XML relativeLayout parameters look like this:
If ever you use the relativeLayout to put views next to eachother or above one another you absolutely have to define their ID's. This is not gonna be relevant for this course it is going to for the next one tho.
From their names it should be more or less clear what these parameters do to your view.
Hope everything's cleared up now
happy coding
Matthias :)