Different screen orientation on different screen size.


There are many tutorials around on web which tells how to support different screen sizes in android. But there are many tiny little real problems which comes in every day life of android developer while supporting different screen size.

Well I understand we can create different layouts & values for different screen sizes which will ensure my screen is properly scaled and fits properly in different screen size. It also ensures the flexibility of amount of information being displayed on different screen size.

Now if we want the application to appear in portrait on small & normal screen sizes, but if the screen is large or xlarge we want the application to appear in landscape, then how do we go about it?

At first I thought that probably defining different screen orientation in different value folder will get this done. But unfortunately it does not work on all android devices.

So the only method left for us to achieve different screen orientation on different screen size is programmatic.

What we need to do is – at the time of activity creation, get the screen size and accordingly set the orientation.

                int layout = getResources().getConfiguration().screenLayout
				& Configuration.SCREENLAYOUT_SIZE_MASK;
		if (layout == Configuration.SCREENLAYOUT_SIZE_XLARGE
				|| layout == Configuration.SCREENLAYOUT_SIZE_LARGE) {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
		} else {
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		}
About these ads

Tagged: , , , ,

6 thoughts on “Different screen orientation on different screen size.

  1. Emmet McPoland July 29, 2012 at 12:52 am Reply
    • Chitranshu July 29, 2012 at 2:58 pm Reply

      Thanks for pointing.. Looks like these steps doesn’t work on all device. Will be editing this post pretty soon.

      • alexander September 30, 2012 at 10:12 pm

        DRAG and DROP on android. need help please, im new to android .. i want to display the description of the item that being drop .. for example, in this link : when i trash the dog1 , in other textfield will display “dog1 deleted” .

        http://capdroid.wordpress.com/2012/07/18/android-drag-and-drop_tutorial/

        help please ! :\ thanks in advance .

    • Chitranshu July 29, 2012 at 3:06 pm Reply

      Updated the post. Hope it will be helpful.

  2. Douglas Gregor April 16, 2013 at 10:07 pm Reply

    I have been going around in circles trying so resolve this problem. Your solution is not suitable for API 3. Do you have a work-a-round?

  3. www.scribd.com June 19, 2013 at 10:20 am Reply

    Hey there, You’ve done a great job. I’ll certainly digg it and personally recommend
    to my friends. I am sure they will be benefited from
    this web site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

iOS tips and tricks

Smile! You’re at the best WordPress.com site ever

Welcome to Mobile World !!!

It's all about being in Mobile Eco System

More Is Not Always Better

Bill Lahti's thoughts on software design and the web.

Going Beyond Windows........

Get the latest tips, tricks, troubleshooting, tweaks and download information here + Now get updates related to Android too :)

Super Mekanismo

Technology, Programming and Life by Kris Viceral

notes of my knowledge

Sharing knowledge, sharing of the world

Angelism

Not just another WordPress.com weblog

sriamit

Just another WordPress.com site

Tech Filled Fantasy

One stop shop for all your tech-filled pleasures!

Android Desk

Just sharing my knowledge on Android

Luthfi Hariz

Mahasiswa tingkat akhir.

Toxik's Corner

Thoughts from the Nerdy Gamer & Poet

androtuto

best blog for android learner

fundroiding

Providing Solutions for Android Problems

Abhik - Mobile Application Developer

Always looking for innovation

Android Developers Blog

with Chitranshu Asthana

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: