Widget does not fit in Jelly Bean - android

I have a widget which was made for Android 2.3.
It has these dimensions:
android:minHeight="76dip"
android:minWidth="146dip"
The problem is that Google has changed the height of a cell in Jelly Bean or even in ICS.
A cell is now 40dp and 2 cells 110dp. This makes my widget streched to 110dp. This looks very ugly as it is streched a lot.
If I increase the fontsize on my widget and the spaces, I can make it fit in the 110dp height. But then it will look ugly on Android 2.3.
I am wondering how I can adapt the widget to look nice on JB AND on Android 2.3. Is there a recommended guide?

Every device may have a different grid size. The only foolproof solution is to use flexible layouts, 9-patch drawables, etc.

Related

android sdk. Background image fits. Foreground images too small

I have my view built to fit a phone screen 800x480. The background PNG shows up as a perfect fit. I have a bunch of imageViews of PNGs sitting on the view that should line up perfectly on any screen that is that size.
When tested on my phone, it works fine. However, when tested on my 7" tablet that has the same screen resolution, the backdrop fits as expected, but the imageViews are all too small.
Why wouldn't they fit the same way, considering the resolution is the same?
Could it be the aspect ratio of the second screen?
I know that when I developed an app on my Note I, it showed up differently on almost every other device with the same resolution, on account of the aspect ratio of the Note I being so wide.
Can you check and see the actual pixel ratio of your second device?
Also, is it showing the on screen action bar thing? The back/menu/etc bit? Because that could be because of the version you're targeting is less than the version of your 7" device, causing it to run in backwards compatibility mode. That'll squish your layout a bit as well.
I have a partial answer to this.
I couldn't find a way to set the size of the PNG itself. Only the ImageView height and width. So I set those to 90dp. I tried px first. Don't do that. It's no good.
But, check this out... Forcing the size in dp made the images show correctly on the tablet, but enormous on the phone! So, it more or less reversed my problem.
But at least I know what the problem is now. I just have to create a secondary view for 7" screens to set the imageView sizes. Or, I'm thinking there must be a way to do this problematically. Before the view launches, detect the screen size, if it's not a phone, change the height and width accordingly.
That should work because, as I mentioned in an earlier comment, the relative positioning is perfect. It's just the size that's incorrect.

Different WIDGET margins on different phones with android 4.0-4.2?

I've small problem - I've and app (home screen widget) for android ICS and higher. But different phones with different OS version (4.0.4, 4.1.2, 4.2, etc) and also different brands (Samsung, HTC, LG, ...) makes my app look diferent.
Ok, it doesn't happens always, but on some phones just Android adds automatic margins to my own - and on some not!!! How is this possible, and how to avoid this? Looks like every brand does it in their own way - which is fine for them, but bad for me :)
EDIT:
I use dp, not px. The main problem is not in dp/px nor in portrait/landscape changes. Main problem is, that for example on phone1 my widget has NO margins (it's like sticked to screen borders) and on other phones it has automatic margins like it should. When I add my own margin to widget provider, it has this margins on phone 1, but on other phones it has (my margins + automatic margins). Hope, now it's clear :)
Welcome to Reality show, when the Android it isn't platform independent, either Java it isn't.
For this reason a single android layout.xml should use elements which are doing layout acceptable in all targeted devices. The screen ratio differs, the dpi differs the resolution differs... As best practice:
use dp size instead of pixels
do different layout for portait and landscape case
have multiple folders based on screen size ( and different layout)
I hope it helps!
well, to close this answer - it looks like there is really no option to have same margin on all devices - as different devices uses different home screen implementation. I can't do anything with that...Closed.

Size images properly for mobile devices

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.

Getting minWidth (appwidget-provider) across all devices, phones and tablets

My android application (Banner) uses widgets sizes from 1x1 to 8x1. I'm getting annoyed with trying to get the magic minWidth set in the XML appwidget-provider files.
Old school method to get widget minimum size was something like [74 x (n) - 2]. Now the method is [70 x (n) - 30]. Neither of these work well past 3x1 widgets. 4x1 if set correctly on a phone usually becomes a 3x1 widget on tablets because of dpi/density/size, etc.
So I ended up placing xml files as such to adjust width as needed. However, I'm really only guessing that the increased minWidth works with all devices as I only tested on my own tablet.
So my question is this... has anyone figured out the BEST minWidths or methods for making widgets on different device sizes, etc?

Android - QVGA screen hides some pixels

I have a problem with missing pixels on QVGA screen on Android (all versions including 2.2). The original problem was with LinearLayout and margin="1px". It was OK on the normal screen but on QVGA there was sometimes no space between GUI controls, like if margin="0px" and not 1px. So I tried to make the example simple (to be sure that it is not a LinearLayout bug), I have just put transparent (height = 10px) and white (height = 1px) images into ImageViews into the main screen. 25% of the white images are not shown on the QVGA screen. The behaviour on the normal screen is OK. The screenshots are from the emulator but the problem exists on real devices too.
See screenshots on my web page.
Is it an Android bug? Can I do anything with it? Note that my original problem was with LinearLayout and margin="1px". Is there something like margin="1px_that_is_not_hidden"? (pt, dp, dip, ... don't seem to be solution)
Many thanks for a reply.
You are probably in a compatibility mode, where Android is attempting to scale your dimensions for you, rather than thinking that you know what you're doing. It's been ages since I targeted a QVGA device, so I forget the precise details. However, I recommend you read the multiple-screen-size instructions. In particular, you probably need to set android:anyDensity="true" in your <supports-screens> element.

Categories

Resources