Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

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?

like image 806
danj1974 Avatar asked Jul 25 '13 14:07

danj1974


People also ask

How do I manage portrait and landscape on android?

To create the landscape mode right click on the res folder -> New -> Android Resource Directory. Now one pop up will be prompted. Select Orientation Available Qualifiers and then “>>” icon at right side, then select Landscape under Screen Orientation.

How do I force horizontal orientation on android?

Open the AndroidManifest. xml and add the following android:screenOrientation="landscape" e.g. Show activity on this post. To do this at the Activity level, in case you want to change it dynamically or allow the user to select the orientation, use setRequestedOrientation in your Activity's onCreate method.

How do I change the default landscape in android Studio?

Step 1: Open the base UI layout in DESIGN mode so that you see the actual GUI, such as Buttons, icons, etc. Step 2: Click the icon marked in the below screenshot and, from the menu, select Create Landscape Variation. Then the corresponding Landscape file will be created automatically named as land\xml file name.


1 Answers

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

like image 149
danj1974 Avatar answered Oct 05 '22 22:10

danj1974