1

i am developing one android application,there i need to change layout of activity at run time

i want to know about ,how to change a layout of an activity as view mode change from portrait to landscape or visa-verse

please anyone tell me what is feasible and efficient solution for above problem. Thanks in Advance

4 Answers 4

2

Best approach is to have a folder for landscape orientation also, you will name it like

layout-land

you will put another main.xml inside that folder, android framework will automatically select that layout for landscape orientation.

More info here from android guide for supporting multiple screen

0
1

Code for detecting orientation change

 @Override
        public void onConfigurationChanged(Configuration newConfig) {
            super.onConfigurationChanged(newConfig);
            if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) {
                SharedVariables.isScreenOrientPotrail=false;
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

            }
            else if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES){
                SharedVariables.isScreenOrientPotrail=true;
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

            }
        }
0
LayoutInflater inflater = context.getLayoutInflater();

                View rowView = inflater.inflate(R.layout.your_dyanmic_layoutid, null, true);

add rowview to your mainlayout.

0

i am pasting code here..try this..

public void onConfigurationChanged(Configuration orient) 
    {
        super.onConfigurationChanged(orient);

        // Checks the orientation of the screen
        if (orient.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
                      //code here for LANDSCAPE..
        ));   

        }
        else if (orient.orientation == Configuration.ORIENTATION_PORTRAIT)
        {           
                      //code here for PORTRAIT ..   
            }               
    }

CAll Method;

  @Override
public void onCreate(Bundle savedInstanceState) 
{
        onConfigurationChanged(getResources().getConfiguration());
    }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.