tags:

views:

52

answers:

2

i want to change layout without calling the onCreate method. i also define android:configChanges="orientation|keyboardHidden" in my activity and it is not calling the onCreate method but the layout not adjust appropriately on landscape mode.

my current layout look like as follows.

alt text

after change orientation as landscape it look like as follows: alt text

but on landscape i want the following result.

alt text

is there any auto adjacent property?

how can i do it?

A: 

I'm going to assume you're using a LinearLayout, because you didn't specify, but there's a function in the LinearLayout class called setOrientation() that should fix this. You'll have to create an instance of your layout in your java file (which you may have already done) and then create either an orientationchange or resize event listener on your window. After that it's just changing the orientation to horizontal/vertical based on screen orientation.

IronFerret
i am using TableLayout. is this possible in linear layout.
Kamran Omar
if it is possible through LinearLayout, please provide me sample code.
Kamran Omar
yeah, it's way easy to use LinearLayout, you can find source code anywhere
Steven Shih
A: 

Hi,

there is no auto adjust property while view changes from portrait to landscape.

For images that you want to display in landscape mode

Create one filename.xml file and design your layout for landscape mode. Give filename same as your previous xml file in layout folder that you are using for activity.

Create folder in res/ name as layout-land and then keep that filename.xml file in res/layout-land folder

It will automatically call that res/layout-land/filename.xml when orientation changes from portrait to landscape.

Or you can also use

    @Override
    public void onConfigurationChanged(Configuration newConfig) {

      super.onConfigurationChanged(newConfig);

      if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
          //your code
      } else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
         //your code
      }
    }
krunal shah