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

  • Home
  • SEARCH
  • 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 9055423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:57:03+00:00 2026-06-16T13:57:03+00:00

My app have two different layout for portrait and landscape mode which both encapsulate

  • 0

My app have two different layout for portrait and landscape mode which both encapsulate a webview and some buttons. Buttons are at bottom in portrait and at left in landscape so more reading space is available in webview.

The problem is, the activity is recreated on screen rotation and webview loads the first page which is not a wanted behavior.

I searched and found out using android:configChanges=”orientation” in activity tag prevents recreating of the activity. But the porblem is it prevents the layout changing too as it happens in activity creation.

I want my program to work in 2.2, waht’s the best way to this?

  • 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-06-16T13:57:04+00:00Added an answer on June 16, 2026 at 1:57 pm

    I tested fragments, but dealing with fragment makes things much more complex and the fragment itself needs saving and restoring which may not work in a webview which has javascript state, So I searched more and find a nice article somewhere and with some modification I came to a solution which I suggest:

    First, add android:configChanges=”orientation|screenSize|keyboard|keyboardHidden” to manifest so app handles the config change instead of android.

    Make two different layout for lnadscape and portrait mode and put them in corresponding layout folders. In both layouts instead of webview place a LinerLayout which acts as a placeholder for webview.

    In code define initUI method like this and put every thing related to UI initialization in this method:

    public void initui()
    {
        setContentView(R.layout.main);
        if (wv == null) wv = new WebView(this);
        ((LinearLayout)findViewById(R.id.webviewplace)).addView(wv);
        findViewById(R.id.home).setOnClickListener(this);
    }
    

    If the webview doesn’t exist, it will be created and after setContentView(R.layout.main) it will be added to the layout. Other UI customization came afterward.

    and in onConfigurationChanged:

    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        ((LinearLayout)findViewById(R.id.webviewplace)).removeAllViews();
        super.onConfigurationChanged(newConfig);
        initUI();
    }
    

    In onConfigChange First the webview is removed from old place holder and initui will be called which will add it back to the new layout.

    and in oncreate call initui so the ui will be initialized for the first time.

    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        initUI()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app and I need to have two different themes for
I have a two different ways of representing data in my app: via UITableView
I have a clojure/ring project that has two distinct app/handlers running on different ports
Hello i have a app which makes 3 wheels from 3 different arrays of
In my rails app, I have two layouts/controllers for different actions. Eseentially, I match
I have two app's projects in two different Eclipse's workspaces. When I run one
Is there a way to have two different Java code for one Android app?
I have two different layouts in my app, one for javascript (AJAX) requests and
Im building an app with a tab-layout. And i have some concerns about tab-layout
In my iPad app I have two textfields. One displays the normal, default textfield

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.