7 inch tablet orientation query - android

I have created an android app which works fine on phone (portrait) and on 10 inch tablet (Landscape). But problem is with 7 inch tablet.It opens in portrait mode but uses UI of tablet..so UI is looking totally distracted. I want to open app in 7 inch in landscape mode..how could it be possible through code...? Any suggestions would be appreciated,. Thanks in advance.
Manifest file declaration ---
<activity
android:name=".MainActivityTheme"
android:label="#string/app_name"
android:screenOrientation="nosensor" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Create a folder in /res directory as layout-xlarge-land and another one as layout-large-land , keep the same file in both the folders and you are done.
These are recommended folders where you should put your files , this is not the complete list but it can be appended with many ,
layout-xlarge-land landscape for 10 inch tablets and 10.1
layout-xlarge-port portrait for 10 inch tablets and 10.1
layout-large-land landscape for 7 inch tablets and 7.1
layout-large-port portrait for 7 inch tablets and 7.1
move your layout file between these folders to properly use it.

I'd better leave a comment, but have not got enough reputation yet.
You should define some layout in layout-land directory, not only layout-land-large.
Looks like your tablet has non-large screen, and there is no layout for non-large landscape mode.

Finally, I got my answer. I changed my manifest file...like
<activity
android:name=".MainActivityTheme"
android:label="#string/app_name"
android:configChanges="keyboardHidden|screenSize|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and dynamically changed orientation mode... like
if(isLargeScreen(this))
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
else
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And moved all layout files in layout-large folder instead of layout-large-land.
Thank you guys for help.

Related

LibGDX Game set to landscape, but showing up as portrait only on certain devices

I’m making a LibGDX (1.9.9) game that is meant to be fixed in landscape mode, but when I run it on certain devices, it shows up in portrait mode.
I’ve tested it on several physical and virtual devices ranging from Android 4 to 11 as well as on an iPhone simulator through RoboVM (2.3.9). This happens on an android virtual tablet (Android 11) and the iPhone simulator. It has gotten stuck in portrait a couple times on a physical device as well, but I have not been able to reproduce it. I haven’t been able to understand why this could be.
I have landscape (android:screenOrientation="landscape”) set in the android manifest.
Gdx.input.getRotation() returns 90 when it is properly set on landscape, but 0, when in portrait so perhaps I can try checking if it is 0 and change the rotation dynamically, but I have not been able to find out how to do that either.
I’ve tried a workaround where I check if screen width < screen height and rotate the camera 90 degrees if that is true to put it into landscape manually, but that causes the camera to become distorted in the manner shown below even though I know I’ve modified the aspect ratio correctly for the rotation.
How camera distorts when trying to rotate to landscape
I am using OrthographicCamera without any Viewports.
// Screen dimensions
width = ((float) Gdx.graphics.getWidth() / (float) Gdx.graphics.getHeight()) * GameSpecs.WORLD_HEIGHT;
height = GameSpecs.WORLD_HEIGHT;
System.out.println("width: " + width);
System.out.println("height: " + height);
System.out.println("orientation: " + Gdx.input.getNativeOrientation());
System.out.println("rotation: " + Gdx.input.getRotation());
// If showing portrait and needs to be rotated
rotateForProperLayout = width < height;
if (rotateForProperLayout) {
height = ((float) Gdx.graphics.getHeight() / (float) Gdx.graphics.getWidth()) * GameSpecs.WORLD_HEIGHT;
width = GameSpecs.WORLD_HEIGHT;
}
cam = new OrthographicCamera(width, height);
// Rotate camera to be in landscape
if (rotateForProperLayout) {
cam.rotate(-90);
}
cam.translate(cam.viewportWidth / 2f, cam.viewportHeight / 2f);
cam.update();
My Android Manifest...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydev.mygame” >
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:isGame="true"
android:appCategory="game"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.mydev.mygame.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation=“landscape"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize|screenLayout">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Any help in trying to understand the reason for this or possible workarounds would be greatly appreciated. Please let me know if I should clarify anything or provide more information.
Thanks in advance.
Since no ones helped you so far I'll post my android manifest, you should maybe post yours since this is almost certainly where the problem is. I set this up a long time ago and, to be honest, can't really remember exactly why everything is set as it is, but it works for me. Note: I use device rotation to control my game in some modes.
As for your manual screen rotation issues, you could access the cameras projection matrix and scale it accordingly to get it looking ok. I do not recommend this though, since it is difficult to track how screen resize calls should alter your layout when you also have to track screen rotation. You would have to consider if the width change should actually be considered a height change when in portrait mode and vice versa (depending on your game complexity). I would recommend just sorting out your manifest. Good luck.
android:screenOrientation="fullSensor"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/GdxTheme" >
<activity
android:name="com.funferret.tr.AndroidLauncher"
android:label="#string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|navigation|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

How can my Android app be optimized for different screen resolutions?

i'm building my first app and i wanna make the app to be optimized for all screen resolutions.
So, i'll tell you what i think i should do -in order to make my app work- with what i've found so far, but i don't feel like i've understand that despite some relevant posts that i read.
I've made the background image at 480 x 800 pixels for high resolution (hdp), 320x480 for medium res (mdp), 240x320 for low res (ldp) and 600x1024 for xhdp(??).
Then, if i put each one on the right folder in the "res" directory...for example "drawable-hdpi" for high resolution etc...will it work?
Are these the right dimensions?
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.etking.winningnumbersgenerator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.etking.winningnumbersgenerator.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
(Please notice the supports-screens)
And my activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.etking.winningnumbersgenerator.MainActivity"
tools:ignore="MergeRootFrame" />
Is it correct the way i described above?
What do i need to do? Please help me with my first app!!!
P.S: If you need something else from the code,ask for it
EDIT: (Please read only below)
I have read Android "Supporting Multiple Screens" but maybe was something i didn't get.
I created a background image for each drawable folder: 240x320 in drawable-ldpi folder, 320x480 in drawable-mdpi, 480x800 in drawable-hdpi, 640x960 in drawable-xhdpi and 1200x1920 in drawable-xxhpdi.
The app displays well on the below screens (using emulator):
768x1280 xhdpi - 4.7'', |
480x800 hdpi - 4.0'' , |
240x432 ldpi - 3.4'' , |
1080x1920 xxhdpi - 4.95'' (Nexus 5) and
320x480 mdpi - 3.2''
It does not look well on:
480x800 mdpi - 5.1'' and 1200x1920 xhdpi - 7'' as it has too much space in the middle down to the bottom of the image.
and also on
240x320 ldpi - 2.7'' the button nearest to the bottom is almost cropped as it is appeared down on the bottom of the screen.
Note that the background image displays well.
I've put layout_width="230dp" and layout_height="50dp" for the button.
Plase help me on this!
P.S: I'm not allowed to post images so you could understand better :(
I suggest you read the Developer Guide on developing your app to support multiple Screen Sizes. It will help you very well not just focusing on screen size, but also on screen DPI (Density per Inch)

Android app won't start (displays a black screen) on Nexus 7

I'm writing an Android app using Gameplay3D. I can compile fine using NDK and generate APK using ANT (both debug and release). The app installs, starts and runs perfectly on a Galaxy S3 and a Nexus 4, but when I try to start it on a Nexus 7 it just doesn't display anything. Just a black screen with the nav bar at the bottom.
I have two Nexus 7s, each with a different version of Android (one is 4.3, other is 4.4).
I'm not highly experienced with Android development, but here is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.secretCompany.secretGame"
android:versionCode="15"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- This is the platform API where the app was introduced. -->
<uses-sdk android:minSdkVersion="10" />
<uses-feature android:glEsVersion="0x00020000"/>
<application android:icon="#drawable/icon" android:label="#string/app_name" android:hasCode="true">
<!-- Our activity is the built-in NativeActivity framework class.
This will take care of integrating with our NDK code. -->
<activity android:name="android.app.NativeActivity"
android:label="#string/app_name"
android:configChanges="orientation|keyboardHidden"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="landscape">
<!-- Tell NativeActivity the name of or .so -->
<meta-data android:name="android.app.lib_name"
android:value="secretGame" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I've changed the game's name and company as they're currently a secret, but other than that this is exactly how it appears in the file.
Any help would be greatly appreciated :)
Additional Info:
The only thing the app does is render sprites and accept input. No sound, no internet, no nothing else.
Both Nexuses (Nexi? :P) are the 2012 edition, not the new 2013 version.
I use render-to-texture. Could this be a problem? Maybe with non-power-of-2 textures?
I tested and the code is still running, I just can't see anything.
AH finally, I figured it out myself, from this post. The problem was that almost all of my textures were not power-of-2 and the ones that were were off screen at the time.
Silly me.
Edit: Or maybe not... now it won't display ANYTHING, not even the textures that were power-of-2 before... does an OpenGL FBO have to have a square texture to work on power-of-2 devices?
Edit2: Ah, ok I finally found the problem. I was correct initially about the sprites not having power-of-2 textures, but then I re-enabled my render-to-texture and it stopped working. Turns out the problem was that I was rendering to a different FBO and then extracting the texture to turn it into a sprite and render into the primary FBO...and of course the texture wasn't power-of-2. I just created the texture at the lowest PO2 size that the entire screen would still fit into, then modified the UV coords of the fullscreen sprite so the extra texture parts were put offscreen. Problem solved!

Android Application portrait mode

I am developing an android application. This Application is in Portrait mode. I changed the manifest file like below
<application android:icon="#drawable/icon"
android:label="#string/app_name"
android:theme="#style/customTheme"
android:allowBackup="true">
<activity android:name=".Favorites"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DBHelper">
</activity>
<activity android:name=".Find"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
</activity>
</application>
which is working fine upto large screen. When I opened it in Extra-large screen the screen is not coming good, i.e all the controls in the view are diagonally cutting.
see the image:
When I remove the android:screenOrientation="portrait" tag from the manifest file my Xlarge Screen is appearing normally. I am not able to understand the problem exactly can any one help me in solving this. I want my application should be in portrait mode only.
You need to provide layout for xlarge-port..So that ur layout can adjust in xlarge screen.
You can keep different layouts for different screen sizes,For that you need to create different layout for different screen size and put it into different folders named as
layout-large : for portrait mode of large size screen
layout-medium :for portrait mode of medium size screen
layout-xlarge :for portrait mode of xlarge size screen
layout-large-land :for landscape mode of large size screen
layout-medium-land :for landscape mode of medium size screen
layout-xlarge-land :for landscape mode of xlarge size screen
Now Android OS will choose appropriate screen automatically.

What images and resource qualifiers do I need to use to ensure that I have a full-screen splashscreen?

I'm writing an application that needs to display a full-screen splashscreen image on start. Actually, not exactly full-screen, because status bar is still visible.
This application will be run on a wide range of phones (e.g. from Wildfire to Sensation), but not on tablets. Though, if it can be made to look good on tablets without much effort, I will do that of course.
The problem is - how can I make sure that this splashscreen looks good and fills the entire screen on all devices? It has stretchable parts on all sides, so I can make it a 9-patch if necessary, but I'm still at loss on what pixel sizes I should use.
I resolve that I need to provide images for (small|large)-(ldpi|mdpi|hdpi). What pixel sizes of those images should be? How to calculate them?
I have done it in multiple applications that i made an image of 480x800px and then took an image view or linearlayout and gave it fill_parent attributes in widht and height. It worked perfectly on all types of screen
[EDIT] One thing more just add that image in hdpi folder only.
For Splash Screen in your xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/splash"/>
</LinearLayout>
and in your AndroidManifest.xml
<activity android:name=".Splash" android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
The Theme.NoTitleBar will also remove the title bar from the splash screen
And for the image for splash screen use images of sizes:
As i had read somewhere and then used
For Portrait: 600 x 1024 px
For Landscape: 1024 x 600 px
I use these sizes in my app and have tested them on android versions 1.6 to 2.3 in each version the resolution of the images appears excellent
In the end, I found out that if I provide an hdpi image, it will auto-scale down for lesser dpi. So, to avoid complications, I created a 800x800 image with croppable sides and used it.

Categories

Resources