I have a question about checking layouts on Android. I know all basics about screen sizes (size vs density), I usually make layouts with listview or scrollview, so no matter height of device it'll just show more or less content. Problem is I often have a particular layout to make (from iPhone "render" usually). Let's take an example:
I had to made 3 buttons in one row, so I've made LinearLayout with 3 buttons inside, which has layout_width 0dp and layout_weight 1. That did the work. Or it seemed to. I use Android Studio (latest version) to build my layouts, so I can see a preview on different screen sizes and densities. I used "Preview all screen sizes" as well I've looked into "Generic phones and tablets". All were good. However I've sent my apk to a friend, which send me a screenshot that showed one letter from buttons went down to a second line. I was using;
android:textAppearance="#android:style/TextAppearance.DeviceDefault.Medium"
His phone is LG L65. I had to make font size smaller, because it appeared really big and didn't fit. How can this be even smallest densities were all good and on this phone wasn't? How can I be sure any layout will fit? Isn't using built-in font sizes a good idea? So I have to own a lot of devices and make different font sizes, margins etc for all combinations of screen sizes and densities?
You have to take in account that the font size can be bigger than expected by a system settings. If you want your button to be single lined, you can use android:singleLine="true" on your button. This might ellipsized the text if needed.
If you want single lined button without ellipsized, you have to build a custom view that down scale the text when needed ...
Related
Is it standard to make buttons text and other views text larger in tablet size? I make dimens.xml for different device sizes and make different text sizes for different device sizes. for examle in normal dimens file:
<dimen name="small_text_mobile">14dp</dimen>
and for large size dimens file:
<dimen name="small_text_mobile">18dp</dimen>
and use this dimens for my textViews and buttons , extra..I want to know if it is standard? or no need for that and texts of views like buttons should be in same size in different device sizes?
The unit used (dp) will convert the button and layout sizes to appropriate pixel sizes on the actual device (making them independent of actual device screen size). Therefore, on a small device it will look relatively similar to a large device. However, depending on the situation, it may be more efficient use of screen space to have different dimensions/layouts for different screen sizes. It really depends on the view being used and the level of user experience required for it. A lot of the time dp will get the job done close to what you would want. The Android documentation on supporting multiple screen sizes is excellent in explaining all the different situations and control a developer could have on their layouts.
Depending on the layout, it may be better practice to create multiple layouts to fit small and large screens in different orientations. It depends on the layout and how complex it is. If it looks unnatural on a certain device, I would recommend creating another layout (or applying some changes on the current one) to better fit all devices.
I am working on a app in which there are some textfiels and button when I am running it on different screen size devices it is showing unexpected result as shown in the below image!
[Image 1] http://oi45.tinypic.com/25yvon4.jpg
[Image 2] http://oi45.tinypic.com/xmlqns.jpg
Here in first image some space is left vacant at the bottom due to large screen size and in second image the last row of buttons are hidden due to small screen size.Also for buttons I am using Table Layout.
Is there any way to solve this problem.
That's a broad topic that needs spatial understanding first.
Here's a good place to start - http://developer.android.com/guide/practices/screens_support.html
Long story short, always use point units (dps), try to avoid to hardcoded pixels within your code, position items in a relative way (ie.: in relation to other object - RelativeLayout, LinearLayout, etc) and make sure to take advantage of the power of "values-..." folders.
Example
values-xhdpi (XH)
values-hdpi (H)
values-mdpi (M)
values-land (Landscape)
values-sw600dp (smallest width at least 600dp)
....
Use layout, layout-large and layout-xlarge resource folders to customize your layout files if you care about various screen sizes. Test these layouts on phones, 7" and 10" tablets to cover all of your bases.
For small phones of less than 4" screens (qvga) as well as older devices (wvga), make custom layout files (in the layout folder) and refer to them dynamically in your java code when you detect these kinds of devices. Again, test on these older & smaller phones as much as possible. Borrow some phones from the Sony Device Loaner Program in order to get real-world testing done.
Lastly, use ScrollView to embed your layouts if you want vertical scrolling on smaller screens. Don't go crazy trying to fit everything on a smaller screen. Sometimes scrolling is a natural solution that your users will understand.
You must have to make screen for all devices if you want to solve your problem.Read below document for different screen:-
http://developer.android.com/guide/practices/screens_support.html
or
You can use weight or layout weight to prevent this problem.
I am currently putting together an application for my HTC Evo 3D phone which has a screen resolution of 960x540. I have set up a custom layout configuration for designing the interface at this resolution. When in this configuration the widgets (texts views, seek bars etc.) appear small and compact, sparse on the screen. Whereas when I launch the application on my phone the buttons are considerably larger and fill the screen more. Is there some setting in Eclipse that will allow me to view the layout in the editor exactly as it would appear on my phone, allowing for easier design of the interface.
Many thanks, Mat.
with relevant code would be easer to help, however, if you are using dp unit measure, sizes will change according to resolution:screensize, not just resolution. I think also a "wrap_content" given to a textview/button etc. would change in size, because font size would be in sp. So, look if there is any emulator configuration that fits real device resolution AND screen size.
Take a look here for more info about measure units.
EDIT
so are you seeing it in eclipse in the graphical layout of yourlayout.xml? on the top bar of that window there's a dropmenu for display configurations, change it to see the layout in different screens (I don't see any 960x540 btw). however, if you really want to develop for one single device is a matter, but if you're going to release the app for different devices, you need some strategy to make flexible layouts. this is very useful.
Currently i'm trying to develop a mobile app for the Android devices (using Appcelerator).
There are alot of Android devices out there with different screen resolutions. So i basically want the app to look the same on every Android device.
So suppose i have a background image in the center of the screen. Which is (in pixels) 550x300.
I just tried to set the width and height of the imageviews to dips (density independent pixels). So in my case to: 332dp x 226dp.
I tested this first on an HTC One X. In there the image in nicely centered and i have a small space left on the left and right side to the edge of the screen.
Then i tested it on a slightly older device, the HTC Desire Z. In there the image width is a little bit more than the actual width of the screen. (example screen. The blue square represents the image)
So that means setting the width and height as dp isn't a good choice either for images.
What would be a good way to set the image width and height so that it looks the same on both phones. i.e., so that they both have a small white spaces on the other edges of the image left (like i have now in the HTC One X)??
Any advice on this matter?
edit
Thanks for the info so far. Some of you posted links to resources etc and made some suggestions. I'll try to work them out in the next few days, so i might take a couple of days before i accept an answer. In the mean time, any ideas suggestions are welcome.
Use the various drawable folders, i.e. drawable, drawable-large, drawable-xlarge to store your image assets for your background in various sizes. Review http://developer.android.com/guide/topics/resources/providing-resources.html for more information.
Also refer to Android: Scale a Drawable or background image? for helpful information.
I would recommend using a size to fit.
in objective c it looks kinda like this... not much of a android programmer but this may help.
CGRect frame = _textView.frame;
frame.size.height = _textView.contentSize.height;
_textView.frame = frame;
so if you could figure a way to get the frame size then you could set your image to that size any way the view is positioned.
and if you dont want it to take up the whole screen and just the sides then there might be a autoresizing function for android this way your image will be flexible with your frame which will vary based on the phone size.
I think the is problem is not that the image is wider, but the screen width of the phone is smaller on the HTC Desire Z.
I think the best way fot the image to look the same on all devices would be to set width/height programmatically.
But I think this doesn't really matter, as you will encounter much more complicated problems further wil developing for multiple devices. Both look good IMO.
What I would is set your android:layout_width to fill_parent and then add a android:layout_marginLeft and android:layout_marginRight in dip. You can also set a margin for the top and bottom, but based on your screenshots that doesn't seem to be an issue.
As a general rule, try to avoid setting fixed heights and widths for your widgets. Here is a great reference for dealing with different screen sizes:
http://developer.android.com/guide/practices/screens_support.html
So i basically want the app to look the same on every Android device.
No you don't. You think you do, but you really don't. That's like trying to fit a photograph in a 4x6, 5x7, and 8x10 frame -- something's gotta give. You have small phones, medium phones, large phones, 7" tablets, 10" tablets -- these are not the same experience and you simply have to allow some leniency to the design to make it work. If you just want a specific amount of space outside of the image, just give your ImageView a specific margin in DP units, e.g.:
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dip"
//...
/>
You should be striving to make the experience the same (although different layouts for tablets are highly recommended) but you can't expect it to look identical across all screen sizes and densities.
I have almost finished my app for android, the problem is when i test it on multiple screen sizes the layout of items such as padding etc, seems to be incorrect. I don't understand how I am supposed to support all screen sizes, because I have used all 'dp' values for the text and sizes for padding etc. I am using the 'background' as an image which fills the screen, and the background includes the layout of buttons and boxes that will have textviews overlaying them. I have been testing on my HTC desire and I have just noticed this issue. I assumed that it would all be okay seeing as I have been using dp for all measurments etc. Any tips to fix my layouts would be appreciated as my app is pretty much good to go apart from this :(
Read the following links very carefully you will get the best way to do:
Supporting Multiple Screens
Support for Multiple Screen Resolutions
Support for additional screen resolutions and densities in Android
compatible-screens
MultiResolution - Multiple Resolutions