appwidget landscape scalling problems - android

I am testing my widget under different configs and devices.
It looks good in portrait mode in all devices that ive tried(160dp,240dp...etc)
However,
in landscape mode i had a problem. The last line of text was getting slightly clipped, so i created layout-land and customized for landscape.
all seemed to be ok, until i tested on 160dp emulator: The last line of text is gone completely! (For text size I am using dip units.)
How do you guys approach this problems? I mean, in 240dp device it looks fine, and on the 160dp the last line is totally clipped.
thank you.

Related

Different layouts for portrait and landscape modes based on screen width, not orientation per se

I have two versions of my layout, for smaller screens and for larger screens. Incidentally, I have a device where different layouts are required in different orientations. On other device that may not be so. I want to base it on screen width, not the orientation as such.
I've read this article and noticed that the "Available screen width" (w<N>dp modifier) can be used for specifying the proper layouts. It also says:
The system's corresponding value for the width changes when the screen's orientation switches between landscape and portrait to reflect the current actual width that's available for your UI.
Sounds perfect. So I put the smaller layout in the base layout folder, and the larger one into layout-w750dp. And the larger layout is picked. The problem is that it doesn't switch to the base layout when I rotate the device into portrait mode.
I have used the code from this answer to check the screen width in dp. It's 960 in landscape and 600 in portrait. Then I made sure android:configChanges="orientation" is not specified for this activity. I have also put Log into this activity's onCreate() - it is indeed called when I rotate the device, so it should have received the correct layout?.. Why doesn't it work and how to make it work?
Update: launching the activity (and even the whole application) in portrait mode right from the start still picks the w750dp layout.
Update 2: layout-land didn't work either. This layout is still picked in the portrait mode. Odd. It's becoming clear that the issue has little to do with width but with general functioning of the resource selectors.
Comments are getting long so to answer.
I just tested on tablet (768x1024 dp) two layouts first in layout, second in layout-w900dp and everything works just fine.
Second layout is shown in landscape mode which is correct because 900 < 1024.
Note: I used getResources().getConfiguration().screenWidthDp for screen width!
So it's definitely problem on your side :)
Ether you messed up your layouts or android studio messing with you :D.
Sorry for lack of more definitive answer :/

Android Studio and a 4:3 resolution

My most resend project involves a Samsung Tab A 9.7" with 1024x768 pixels in a 4:3 format. This tablet is quite new and this format is unfortionatelly not supported by Android Studio so I've tried adding a new virtual device with these resolutions. I've set the scale option to: '1dp on device = 1px on screen'
The thing that seems wrong, is there is a difference between dp and px. If, for example, the width of a view is set to 1024px, it lines up nicely with the borders of the screen. But if I set it to 1024dp, it is much smaller... 1dp=1px means it is supposed to be the same, right?
When I launch it on the tab, all content gets wrong sizes etc (due to the problem above ofc).
Is there a way to propper add a 4:3 resolition so it can be used in the layout editor? I know there is a difference between px and dp but 1/1 is supposed to be the same?
Thanks a lot,
Jesse
After a long mixture between research and trail and error, finally 'found' the cause. When adding a virtual device in android studio for a custom resolution, it automatically focuses on portrait mode I think. Putting a view till the middle in portrait mode inside the editor -> In the middle in landscape on the tablet. Not sure if this is mend to be or an error of some kind.
Found out you can use the Nexus 9 layout, also 4:3 (2048 x 1538).
Thanks for the support Nanoc

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.

Android: Unwanted left/right margins on Nexus 10 in landscape mode

I'm having an issue with seemingly inexplicable margins that appear on the left and right sides of my layouts when using a Nexus 10 device in landscape mode.
I'm sure it's something embarrassingly straightforward, but I can't find any mention of this when searching around.
I'm pretty sure it's not related to my code, because the default Hello World project created by Eclipse exhibits the phenomenon. The following screenshot excerpts are taken from a brand new project and the only change I have made is to make the TextView textSize a bit bigger for clarity:
You can see that the default margins from the layout XML file (shown below) are applied correctly in portrait mode, but there is a considerable additional margin applied in landscape mode - indicated by the red bar underneath the screenshot.
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
Has anyone else seen this or have any idea how I can get rid of them? I don't really know where to start, because it seems to be specific this one device and screen orientation. Plus it affects the simplest program possible, as well as my own, so there's no sense in pulling apart my own code until I find out how to fix the default case.
The same screens display correctly on emulated devices and my Samsung Galaxy S2 (running Gingerbread). Changing the Project Build Target from API level 17 to 10 didn't alter the unwanted effect either. Any thoughts?
Ok, so it was embarrassingly straightforward! The margin for the Nexus 10 in landscape mode is taken from the 'values-sw720dp-land' resource folder, which declares a much larger value:
<!--
Customize dimensions originally defined in res/values/dimens.xml (such as
screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
-->
<dimen name="activity_horizontal_margin">128dp</dimen>
After nearly a year of lurking on SO and finding answers to all my questions, the first one I finally decide to ask properly turns out to be as trivial as this...
Thanks, danj1974! You saved much time for me! I changed a setting in res/values-w820dp/dimens.xml to
<dimen name="activity_horizontal_margin">0dp</dimen>
and it works good.

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