so I'm making a really simple app that just shows some buttons and images,
it looks great on the simulator (because I guess that's the resolution I've been working on ...)
but when I try to build it to my phone it looks differently (the buttons are more stretched out and there is allot more background space in between the buttons and the end of the screen,
I guess it's something that's suppose to be simple but how to I make my app "zoom stretch" to the phone content it's going to be on, meaning it will look the same on any phone and if necessary will stretch the image a bit to fit the screen ?
Thx
In your XML, its important to not use specific(dp,px,etc.) sizes for laying buttons/text boxes/etc. out. For example, for a button thats on the page, use a "layout_width" of "match_parent" and add padding (if necessary from there). This will allow your button to stretch properly without having that extra whitespace.
Related
im developing an android app on android studio, when i run my app the layout looks a bit different from the preview as well as on other phones,
for example: the buttons are in different order (from right to left instead from left to right) or other changes similar to this.
as well as on some phones the layout doesn't fit perfectly on the screen for example: the buttons on the sides of the screen appear to be cut out.
how can i fix it so the app will look the same with every phone and not only some of them?
About the Right-to-left/ Left-to-right, you can choose the globe icon in the preview options bar frame and then choose Preview Right-to-Left Layout option. This will "fix" the buttons order in preview.
About the buttons that appear to be cut out - make sure you use dp units instead of pixels. You can read more about it here:
http://developer.android.com/guide/practices/screens_support.html
Make sure you check if you have used the constraints on your components properly. Usually that's what makes the layout messy after running the app on your phone/emulator, even tho it looks perfect on your XML file.
I'm in the beginning stages of developing my first app and wanted to know what I can do from now to make sure my app runs equally well across all Android devices. I don't have access to another device right now to test whether or not it will scale but have I noticed that if I rotate my device to landscape, the items in the view (e.g. buttons, icons) don't scale at all to fit the screen. This makes me worry that it won't be very compatible with other devices.
I find myself putting items in each view by messing with paddings and margins in the XML till I have it right - but now I realise that this makes the layouts specific to my device. Is there a "correct" way of doin this? For instance, if I had to draw 4 horizontal lines equally spaced across the width of a screen how would I achieve this so that the width between the lines are determined according to the size of the screen?
I have a large image in my MainActivity but for some reason it gets really small if I switch to landscape.
Can anybody shed some light on this? Would be really grateful, thanks.
This issue is addressed here:
http://developer.android.com/guide/practices/screens_support.html
I have a design that I need to follow in my app. In it there are several buttons, images and textviews placed all over the screen (some are aligned to the left, some to the right, some are centered etc). What I need to do is make all those elements appear EXACTLY as they are in the design image. The problem is, if I try to do this using dp, it can be wider or narrower than the design image specifies, and it depends on the properties of the screen. (I've had an app where I did it all in dp, and on my high-res phone it works perfectly, but on my friend's older phone it cuts away the edges of the activity)
My question is, what elements do I use for this? I've heard of using weight in Linear Layouts, but how to make items different width and height and position them all across the screen how I see fit? How to make sure it looks exactly the same on all screen sizes?
Thanks in advance! :)
Edit:
The point is, I need the buttons to be just as they are on the screen (this will be a listview element, I'm trying to make an xml for it). The distance, proportion, everything, it needs to scale to the width of the screen and be this size and distribution. And, I'm not just looking for a solution to THIS particular problem, I want to learn how to do it in general...
You don't. For very large and very small screens, you use separate layouts that scale the sizes, completely drop parts of the UI, or lays it out in a different manner. It's absolutely silly to think you can fit all the stuff on a 10 inch tablet and a 3.5 inch phone. If your designer expects that, tell him he's an idiot and he needs to get back to work.
For a more general answer on the best way of laying things out- it depends on the effect you're trying to get. You should never use pixel counts, and dp should only be used for small things- a bit of padding between 2 fields. Most things should be done via layout, either by using a linear layout and getting things in rows/columns, or a RelativeLayout and describing how to layout views relative to their siblings. But even with these tools you will not be able to fit on all screens and look good.
In my android application, I have a problem that when I run my application, its not fit to the emulator and some part cut on it like below:
And also you can see below I have a button also on it like below image:
But its not show me the full image, means a button is missing on the emulator.
How can I resolve it. kindly suggest me, waiting for reply.
Thanks
Basically, your designer and emulator are using different screen dimensions.
You can change the designer to use the same screen dimensions. Currently, from your screen shot you're using the Nexus One layout. From what I can tell the emulator doesn't look like the Nexus One screen dimensions.
With Android it isn't as simple as 1 layout for all dimensions, screen sizes and devices. You have to implement multi-screen support to address this. You can usually do this by having a variance on dimensions, styles and layouts. A lot of the time one layout will work universally, but dimensions often need tweaking.
See http://developer.android.com/guide/practices/screens_support.html for more on Supporting Multiple Screens.
It is a problem that can occur in real devices (remember, we have loads and loads of different screen sizes for android) so you definitely need to fix it.
The best way to avoid this is to wrap the entire layout inside a ScrollView, so the user can scroll to see all the content of your layout.
If you are trying to fit all the elements on the screen then you need to account for different screen sizes and densities. In your particular case you are building the screen on a different sized screen than the emulator.
Assuming you do not want the screen to scroll (which is solved using a ScrollView), then to fix this, you can do the following:
Build different XML layouts for different screen sizes
Use dimen files to specify different sizes for some or all elements on the screen so that they re-size depending on the screen size.
Use weighted LinearLayout so that Android re-sizes the elements according to the screen they are placed on.
Each of these is pretty easy to search and find various ways of doing.
I want my app to run on a wide variety of android devices in portrait only. I have a whole-screen background image that includes borders for other components. I want to place items like listviews/sponsor ads accurately within those borders... overlay them on top of the background in exactly the right place. Is using Framelayout the best/easiest way to do this? How do I make sure I get the listviews or sponsor ads in exactly the right place, and exactly the right size given that the background will be stretched to different dimensions for different devices? I've considered cutting up the background image instead but that seems like more work. What's the best approach? Thanks for any thoughts!
Unfortunately, this scheme is never going to work consistently across all screen sizes. If you want borders, you need to create 9-patch graphics out of those and assigne them as teh background to the UI item.