Setting up the HTML meta viewport for a full 100% width display

Is there a way to display my website on mobile devices at 100% width in both landscape and portrait views?

I attempted using this HTML code without any CSS styling:

<!DOCTYPE html>
<html lang="hu">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>test page</title>
</head>
<body>
    <div style="width: 1000px; background:#ff0">hello world</div>
</body>
</html>

While it appears correctly in landscape view, the issue arises when viewing in portrait mode as it is zoomed in as though it were still in landscape view.

What recommendations do you have for achieving the desired outcome?

Answer №1

Upon loading your HTML in a basic WebView, everything appears to be functioning properly from my end. It's possible that the issue lies with your layout rather than the HTML itself?

Here is the straightforward WebView implementation I utilized:

<?xml version="1.0" encoding="utf-8"?>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webViewMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
/>

Furthermore, here is the onCreate method I employed to evaluate your code:

WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

webView = (WebView)findViewById(R.id.webViewMain);
webView.getSettings().setJavaScriptEnabled(true);
//webView.loadUrl("http://www.google.com");
String data = "<!DOCTYPE html> <html lang=\"hu\"> <head>     <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">     <title>test page</title> </head> <body>     <div style=\"width: 1000px; background:#ff0\">hello world</div> </body> </html>";
webView.loadData(data, "text/html", Encoding.UTF_8.toString());
}

Answer №2

Regarding your reply to my previous comment:

I am confident that the desired behavior is actually already set as the default. By including width=device-width in the viewport, it mimics the action of resizing a browser window on a desktop.

If you decide to eliminate this portion from the content attribute, it should function according to your preferences.

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

Executing a query within a loop in Back4App (Parse)

Currently, I am in the process of developing a social network application with Parse that will include a follow/unfollow feature. This project involves two primary tables: Users and Follow. The Users table contains all user-related data, while the Follow ...

How can I retrieve HTML with JavaScript enabled?

Seeking to extract the HTML code from a webpage using PHP, I attempted the following: $url = 'http://en.wikipedia.org/wiki/New_York_City'; $html = file_get_html($url); However, an issue arose where Wikipedia failed to supply the <script> ...

Why does the interface vary across different devices within the storyboard area when constraints are applied?

Despite my attempts to properly pin buttons to the edges, tops, and bottoms in Xcode 8, the UI still ends up either stretched or not wide enough when different devices are selected from the storyboard. Can anyone advise me on what I might be doing wrong or ...

The runtime is experiencing difficulty in loading the Bootstrap files

File Structure in eclipse The issue is that the CSS files are not loading at runtime, causing me to lose the design I created. Below is my code for the login page. When clicking on the links for the CSS files, they open in the Eclipse IDE instead of load ...

Creating the code for a button that switches between views using a TabBarController

I am working on an app that utilizes a TabBarController with three tabs, each of which has its own .xib file. Additionally, each tab includes a NavigationbarController to display a navigation bar with a title at the top. I want to add a button (one on each ...

Converting Sound Files to Binary Code Using Swift

Is there a way to convert recorded audio to binary data for uploading to the server? I'm familiar with using pngData for images, but is there something similar for audio files? I've attempted the code below, but I'm uncertain if it's th ...

What is the best way to adjust text to a specific width on an HTML canvas?

Is there a way to adjust the width of a single-line text string precisely on an HTML5 canvas? My current method involves initially setting a font size, measuring the text's width using measureText(my_text).width, and then determining a new font size b ...

In the event that the identifier changes, initiate a fresh iteration of the loop

My query is returning several lines with the same id. Here's an example of the output: Id Amount Owed Description 552 50.00 Diapers 552 35.00 Lotion 545 23.00 Pen 545 15.00 Notebook Currently, I'm looping in Javascript to display t ...

Challenges with saving and retrieving custom objects in NSUserDefaults using Objective-C

My project involves storing and retrieving an Array of custom objects using the NSUserDefaults. However, I am encountering issues in this process. Despite researching extensively on this problem, I have not been able to find a solution. The storing part s ...

The encoding of Base64 in Swift does not translate correctly on Android devices

I am currently facing a challenge with my mobile application. The Android version encodes images using Base64 and stores the encoded strings on a server. Now, as I am developing an iOS client for the same app, I am struggling to achieve the same encoding m ...

"Troubleshooting Xcode Configuration Problems: A Team Member's Guide

A client of mine recently set up a new App-Id using a specific ID. They then added me as a developer to their organization on iTunesConnect. The app they are working on is an older version, and I need to start working on it. However, when I attempt t ...

What is the method for identifying when a user clicks the button on the native scrollbar?

Is it possible to detect the click event of a native scrollbar's left or right, up or down buttons? I am looking to implement custom behavior for the scrollbar, such as scrolling in fixed increments. Although I have tried using the scroll function, it ...

Gather data from a span class (Web Development)

<span class="score" title="286 up, 34 down">252</span> How can I modify the code to display both "252" and "286 up, 34 down"? I am not the owner of the website. Would using a CSS Mod like "Stylish" be able to achieve this, or would I need to ...

Every second, didUpdateLocations persistently calls with deferred updates

I'm currently working on implementing deferred location updates in order to improve battery consumption. I have initialized my location manager as follows: - (void)initCoreLocation { self.locationManager = [[CLLocationManager alloc] init]; s ...

Guide on setting up a shortcut key for an input field

Currently, I have a collection of images each with its own HTML page. I added an input button that when clicked, takes you to the next image. However, I would like to enhance user experience by allowing them to use keyboard arrows for navigation. Being new ...

Tips on disregarding events within an html table

I have a see-through table with a width set to 100% that houses various HTML content. I am utilizing the table to properly center a particular element on the screen. However, the table is intercepting mouse events and preventing users from clicking on lin ...

Measuring the space between components

I am looking for a way to dynamically calculate distance on a canvas, similar to the example shown in the figure. I want to be able to drag the highlighted joints in order to adjust the span for calculating distances. Are there any plugins available for th ...

How can I change the background image using CSS instead of HTML?

I initially created a non-responsive website for an existing project. Now I need to convert it into a responsive site. I tried changing the logo image to make it responsive, but it's not working as expected. <td colspan="2" style="background-image ...

Using Rails and HAML to incorporate looping HTML5 video tags

I have a question regarding how I'm using Rails video_tag to display a video: = video_tag("SMR_video.mp4", :controls => false, :autobuffer => true, :autoplay => true, :loop => true, :id => "hero-video") After implementing the above co ...

Display or conceal Div elements depending on the selected Radio Buttons, with their values retrieved from a database

How can I dynamically Show/Hide Divs based on Radio Buttons with checked values retrieved from a PHP and SQL database? <input type="radio" name="status" value="Ongoing" checked="checked">Ongoing<br> <input type="radio" name="status" value ...