Wednesday
Mar032010
Switching layouts when screen orientation changes in Android
Wednesday, March 3, 2010 at 10:28AM
When a displays orientation is changed you may find that your original layout doesn’t scale well. Every time the device orientation changes you current activity is destroyed and recreated. You can change your layout based on the current screen orientation in onCreate()
private void setContentBasedOnLayout()
{
WindowManager winMan = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
if (winMan != null)
{
int orientation = winMan.getDefaultDisplay().getOrientation();
if (orientation == 0) {
// Portrait
setContentView(R.layout.alertdialogportrait);
}
else if (orientation == 1) {
// Landscape
setContentView(R.layout.alertdialoglandscape);
}
}
}
For more information see Wei-Meng Lee’s article on Dev-X: http://www.devx.com/wireless/Article/40792/0/page/1
Rory |
12 Comments | in
Android
Android
Reader Comments (12)
The article written by you very good, I like it very much. I will keep your new article. replica vacheron constantin watches
WO, good ! I like it very much,but If you can add more video and pictures can be much better, I have never read such a lovely article and I am coming back tomorrow to continue reading emerald bracelet
Our replica rolex watch
are superior in quality and moderate in price and are sure to be saleable in your market,by virtue of this superior quality, this product is often sold out in many areas. This new product is really much better than the previous one. You have to try it to believe it.replica royal oak
-Omega Constellation Swiss watch replicasWhen you are young, you may want several love experiences. But as time goes on, you will realize that if you really love someone, the whole life will not be enough. You need time to know, to forgive and to love. All this needs a very big mind.
Buy discount coach handbags and Coach Purses sale from Coach Outlet store online,we offer elegant and fashion coach free shipping and fast delivery.Coach women's handbags were made out of sturdy cowhide, which was of much better quality than many other bags.
Juicy Couture is known for its sweet and elegant design. Juicy online boutique with a luxurious series of Couture items from Juicy Couture Bags and tracksuits to jewelry and shoes provided for Juicy girls and ladies! Well known for the outstanding designs, upscale quality and impressive cheap prices, our online store will take you enjoy a luxury fashion effortlessly.
Hi! I came across your site accidentally today, but am really pleased that we did! It’s not only entertaining, but in addition straightforward to utilize weighed against lots that I’ve viewed!
Houton Home Security
This is what I have been searching in many websites and I finally found it here. Amazing article. I am so impressed. Could never think of such a thing is possible with it...I think you have a great knowledge especially while dealings with such subjects.
This is what I have been searching in many websites and I finally found it here. Amazing article. I am so impressed. Could never think of such a thing is possible with it...I think you have a great knowledge especially while dealings with such subjects.Home Security
really i like this code......short and simple......
its working for me..
Thanks
how to open selected tab when clicked ? i am using ActivityGroup in my app.
Do u have any solution?
Thanks in advance
I am happy to find this post very useful for me,baseball hats as it contains lot of information Nice,59fifty hats and thanks for sharing this info with us.Good Luck!