Question

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:

Comparison of landscape and portrait orientations on the Nexus 10

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?

Was it helpful?

Solution

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...

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top