Resizing body div to fit screen in iOS using Xcode for Cordova/PhoneGap

Just delved into the world of cordova/phonegap and managed to create my inaugural app. It's a work in progress, but I've hit a roadblock that I am struggling to navigate.

During testing on both the simulator and actual device, I noticed some black margins appearing at the top and bottom (specifically in landscape mode). When I touch these black borders, I can manipulate the content by adjusting it to fit the screen (it exceeds the dimensions but maintains proportions). Consequently, I find myself constantly moving the content up and down to view everything properly (sometimes also from side to side).

Any tips on how to ensure my content fits the screen correctly? Since I do not have a header or footer, all I need is for my body div to adapt to the screen and remain fixed there.

Appreciate any assistance.

Answer №1

To set the size manually, you can define it in the AndroidManifest.xml file

When the configuration switches to landscape mode, the activity is terminated and then restarted. To enhance speed and preserve data, you have a couple of options:

  1. You can create a custom java object that stores crucial state configurations using the onRetainNonConfigurationInstance() method, which is called between onStop() and onDestroy(). This method returns an object that can be retrieved using getLastNonConfigurationInstance() in the onCreate() method.

  2. A similar approach can be taken by utilizing fragments. Since the hosting activity is killed and recreated, it also terminates the attached fragments. To avoid this, add the following code snippet inside the onCreate() method:

    onCreate(Bundle b){
    //code
    setRetainInstance(true);
    }
    By setting setRetainInstance(true), the fragment is retained, detached but not destroyed, hence preventing it from being recreated.

  3. Another way to prevent shutting down and restarting is manual reconfiguration. Specify the configuration changes your activity manages in the "AndroidManifest.xml" file. When a configuration change occurs, the onConfigurationChanged() method is triggered.

Answer №2

After trying various solutions, I finally found one that worked perfectly for me. The key was to make a simple adjustment in my CSS by adding the following lines within the body tag:

position: absolute;
top: -16%;

As a result, my body div shifted upwards on the screen, allowing my content to be positioned correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to modify the standard width of semantic-ui sidebars?

I'm trying to adjust the width of semantic-ui sidebars, which are originally 275px wide. Where should I include the css/js code to make them wider or narrower? Here is their default code: .ui.sidebar { width: 275px!important; margin-left: -275 ...

The value property of the input element is returning as undefined

The input value entered is always returning undefined. Despite trying various solutions found in similar questions, my jQuery code continues to return undefined. jQuery: $( document ).ready(function() { $('#Input').keypress( function(e ...

Connecting a string array to the navigation bar

Need Assistance with AngularJS: In my controller, I have a string array that looks like this: var app = angular.module('myApp', []); app.controller('mycontroller', function($scope) { $scope.menuitems =['Home','About&apos ...

What might be causing the excessive margins in my Bootstrap grid layout?

I've recently integrated Bootstrap into my Angular project using npm, but I'm facing an issue with excessive margins on the sides. Can anyone provide assistance? Below is the code snippet: <div class="container"> <div class="row"> ...

I'm getting a warning for setting the delegate of my FetchedResultsController - what am I doing incorrectly?

Here's the code snippet I'm working with: - (NSFetchedResultsController *)fetchedResultsController { if (!_fetchedResultsController) { NSManagedObjectContext *context = [(AppDelegate *)[[UIApplication sharedApplication] delegate] man ...

What is the best way to assign a percentage width based on a variable in jQuery?

Is there a way to assign a dynamic width value to an element? Here is the code I am using: $(".menu_list_item").css({ width: width + "%" }); Unfortunately, this doesn't appear to be functioning correctly. If anyo ...

Pressing the menu button will trigger a function that halts after the third click

As I attempted to implement the functionality of this left menu bar, I encountered a roadblock. The click event on the menu button seems to work fine initially - the left bar appears with the first click and closes as expected with the second click. Howeve ...

Expand and collapse navigation menu using Jquery

I am currently working on a navigation list that should open and close when clicked. However, I am facing an issue where using nav ul li.test a to open the hidden ul on click is not working as expected. When I try using nav ul li.test without a, the hidd ...

The HTML image tag is malfunctioning on a Windows system

I'm currently updating an HTML page and trying to add an image using the img tag. <img src="file:///C:/wamp/www/images/Sat.png" class="img-circle" alt="User Image"/> However, it doesn't seem to be working! ...

Desynchronization of jQuery

Incorporating a slideshow and a function to modify the appearance of four boxes, the following code is utilized: jQuery(document).ready(function() { jQuery('#fp-slides') .cycle({ fx: 'fade', speed: '2500&a ...

Using the "position: absolute" property will not contribute to the

I am facing an issue with aligning two div elements inside a parent div. Currently, they are rendering side by side: <image><info> However, on smaller screens, I want them to render one under the other and swap positions, like this: <inf ...

Ways to align and fix a button within a specific div element

How can I make the button with position: fixed property only visible inside the second div and not remain fixed when scrolling to the first or last div? .one{ height:600px; width: 100%; background-color: re ...

What is the functionality of 'min-height: 100vh' when child elements stack due to a small width?

In a parent element, I have two child elements: <div id="registration"> <div id="left-panel"></div> <div id="right-panel"></div> </div> The styling is as follows: #registration{ @include l { flex-dire ...

HTML page filled to the brim with data tables

Wrapping up a midterm assignment for an HTML course and facing an issue on the final page. The table is overflowing to the right when the browser isn't maximized, and I'm stumped on how to solve it. Any suggestions? Unfortunately, unable to shar ...

I am attempting to update the background image pattern every time the page refreshes. Despite trying numerous codes, I have not been able to achieve the

Here is my code that I've been struggling with. I am trying to change the image on page refresh, but it's not working as expected. <SCRIPT LANGUAGE="JavaScript"> var theImages = new Array() theImages[0] = 'images/1.png' ...

The specific serviceUUIDs were not triggering the didDiscoverPeripheral function in CoreBluetooth, but it worked perfectly when set to

Currently, I am scanning for bluetooth devices using CBCentralManager in my code: - (void)beginScanning { [self.centralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }]; } - (void)centralMana ...

Using JavaScript to parse an XML document on a WAMP server

I am a beginner in the field of web development and currently struggling with parsing an XML document using JavaScript on WAMP server. I know that both the web page and XML file need to be on the same server for it to work. I tried placing both the PHP and ...

Error in Javascript caused by the use of Jquery's "hide on load" feature

Looking for help with creating a menu where the subitems disappear when the page loads. If you require the full HTML code, I can provide it, but essentially it consists of several DIVs, with the items under headers having a class of subitems. I was able ...

Adjust the size of a nested div within a bootstrap container

My dilemma arises when nesting a product slider div inside a bootstrap col-lg-x div, as illustrated below: https://i.sstatic.net/9tCVA.png The issue lies in the layout distortion that occurs within a div.row > div.col-lg-8 structure, where images are ...

Is there a way to incorporate CSS into an element utilizing jQuery when only a class is available for identification, and when the time in the innerHTML is within a 5-minute range from the current time?

I have some HTML code that I need help with: <td class="mw-enhanced-rc">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;18:10&nbsp;</td> My goal is to use JavaScript to make the time bold. $('td[class^="mw-enhanced-rc"]').eac ...