get current active layout depending on orientation?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

get current active layout depending on orientation?

Postby glr » Sat Nov 28, 2009 9:21 pm

Hey dudes and dudetts

I have a Calculator project going on, so far most things are under control. One thing that I have been trying to get going is the rotation. So before I recive a headache searching around for this I decided to make my first forum post to ask about a code problem.

I included in my AndroidManifest.xml
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. android:configChanges="keyboardHidden|orientation"
Parsed in 0.000 seconds, using GeSHi 1.0.8.4

^I assume "orientation" is the same as "sensor"?

I have in my Calculator.java
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. @Override
  3.  
  4. public void onConfigurationChanged(Configuration newConfig) {
  5.  
  6.           super.onConfigurationChanged(newConfig);
  7.  
  8.        
  9.  
  10.          //TODO: setContentView to either main or landscape depending on orientation
  11.  
  12. }
  13.  
  14.  
Parsed in 0.029 seconds, using GeSHi 1.0.8.4


You probably already figured out what I want to do by reading my TODO. Since my calculation buttons in landscape mode will be the same as in portrait I assumed all I need to do is to have two layout xml.

Portrait: main.xml
Landscape: landscape.xml

So when the user flips it horizontal I want the landscape.xml to be active, and vertical I want the main.xml to be active.

My first thought by going on to this was quite simple, just get what the current layout is set to, if its set to main then change to landscape and vice versa. Is it so simple or do I have to create another java file specificly for landscape mode? Or even if this was possible, would this be a bad idea? I assume there is "one right way" by attacking this problem.

Best regards,
glr
glr
Freshman
Freshman
 
Posts: 9
Joined: Sat Nov 28, 2009 9:09 pm

Top

Postby vovkab » Wed Dec 09, 2009 4:11 pm

You need to remove all code that you write here. And just rename your landscape.xml to main.xml. It should be:
layout\main.xml
layout-land\main.xml
vovkab
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Mar 18, 2009 11:48 am

Using Realtive lay out may help..

Postby sanzeiev » Thu Dec 10, 2009 7:54 am

I don’t think you need two different xml each for landscape and prorate By using Relative layout in stead of other ( linear, absolute..) you can solve this..
sanzeiev
Freshman
Freshman
 
Posts: 8
Joined: Wed Jul 22, 2009 6:08 am

Re: Using Realtive lay out may help..

Postby glr » Thu Dec 10, 2009 9:19 pm

vovkab wrote:You need to remove all code that you write here. And just rename your landscape.xml to main.xml. It should be:
layout\main.xml
layout-land\main.xml

Correct, I just read this in a book a day or so ago. I jumped in an tried it right away but never got it to work properly in my current project. I read this again from you and did a new project, now it seems to be working. Not sure if it had to do with me switching to Google API in second project.

sanzeiev wrote:I don’t think you need two different xml each for landscape and prorate By using Relative layout in stead of other ( linear, absolute..) you can solve this..

I am not sure how this work but it seems a bit more clean if I can keep it in seperate files.

Anyhow, thanks for the efforts.
glr
Freshman
Freshman
 
Posts: 9
Joined: Sat Nov 28, 2009 9:09 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests