Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:30:00+00:00 2026-05-23T08:30:00+00:00

I am a starter on Android and trying to figure out how do use

  • 0

I am a starter on Android and trying to figure out how do use different layout files (main.xml) for portrait and landscape screens.

I tried to put main.xml in both res/layout and res/layout-land, then rebuild the project. However, this doesn’t work for me.

I then added onConfigurationChanged method in the code and setContextView to R.layout.main. This time I got different screen layout in different orientation, but all functionality were lost. Some posting also said using onConfigurationChanged method is not really the best idea.

So can anyone help me with this issue?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:30:01+00:00Added an answer on May 23, 2026 at 8:30 am

    Android will automatically use the layout that represents your devices current state. For your specific project, the layout-land xml file should be used when the device rotates. When you override the onConfigurationChanged method and modify your manifest, it tells Android you will handle the configuration change yourself which I do not recommend, especially if you want a new layout to be loaded.

    Here’s what you need to do (to test for the different layouts). Put an xml file called main in your layouts folder. For the layout, just use a LinearLayout that fills the parent with a blue background. Now create an xml layout file called main but put it under the layout-land folder. In this layout, use a red background.

    Start the app, rotate the device, and you should see the background change colors. This is because the activity is being destroyed and restarted with the new layout.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out what happens to an android service when PowerManager.goToSleep() is
I am trying to use Jake Wharton's ActionBarSherlock to support actionbars in android projects
I'm trying to create a RadioGroup within an Android layout where the child RadioButton
Just started writing java / android and I am trying to use android.widget.VideoView. I
I'm trying to figure out what is the best general design for applications that
I am currently trying to figure out what CallLog.Calls.NEW means. The documentation says: Whether
I am trying to figure out how on earth i can start and stop
Ive inherited some code which started out as an Android project but really is
Still an iphone dev starter but trying. I would like to have the user
Recently started programming Android Java (Eclipse), Im trying to make a simple reader app

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.