phone gap screen images doesn't fit the screen - android

android app with phone gap but the images in the html pages are bigger then the android screen. can u provide me the solution how the icons in the html page will be re sized as per the screen.
Please find the code attached. how to reset the images to fit to screen.
you can download android source code here
https://rapidshare.com/files/422996060/PhoneGap.zip

I noticed that you're specifying an absolute width in your code. If you want to just leave it up to the browser to determine the width, you could do something like this fiddle.
<img src="someImage.jpg" width="100%">
Change the size of the 'result' window and you will see that the images expand and contract to fit the page.
If you need to have exact widths in your phonegap application, you could use this plugin for Android.

you can even do that with:
img {
height:100%;
width:100%;
}

Related

rem units don't work in webview

I've created a simple application using Phonegap for android, that simply loads my website's content. The problem is webview doesn't understand the "REM" css units, even though on the same device when I open the website in chrome browser it works as expected.
The technique I'm using is I set the root font-size in pixels (for example 1px), and everything else using rem units. It looks like when using webview, it has some minimum value for font-size which is far bigger than my value and it multiply all elements sizes by 10-12 times.
Is there a way to fix it without switching to pixels instead of rems?
Code example:
body {
font-size: 1px;
}
.element {
width: 15rem;
}
From the code above, the width of the element should be 15px, which is correct if I open the website in mobile browser, but in webview its bigger than 150px;
UPDATE:
I'm almost sure that it has a minimum font-size issue in webview, because I tried the opposite now, I set the root font-size to 15px and .element width to 1rem and it shows everything correctly, means REM units are working if I set root font-size above the minimum limit in webview.
Here is how my website looks in mobile chrome
[]
Here is phonegap application
Webview increases the minimum font-size by default. This solution works the best for me. Now webview acts like most other browsers with rem units. :)
https://stackoverflow.com/a/41496408/688352

proportional html buttons using css?

How can I have html buttons proportional to screen size?
I am trying to code an android app using html and css, with buttons that produce certain results, and the program runs fine. the only problem is, when I send my friend the file, his buttons are so small that it's difficult to use.
he's gotten tired of me sending him files to try, so can someone please give me the css that makes everything proportional to all screen sizes?
for example, there are three buttons in one row, I want it to look like the same layout, but larger on larger screens, and smaller on smaller screens.thanks.
I probably should have mentioned this, but the px I changed was in the font size located in the body tag.
Use percents to define specific button proportions.
.button {
height:10%;
width:10%;
}
Would get you a more accurate and preferred result than:
.button {
height:100px;
width:100px;
}
The only reason you would get different on different browser sizes is if you defined the button sizes as specific pixel sizes.

Android WebView content scaling

I have same applications on two devices with different screen sizes, one is 1024x600(180dpi), another is 1280x800(213dpi). This app contains webview with dimensions specified in pixels. On first device it is a little smaller. The problem is that when I load my custom html page, on first device with smaller screen and webview the page is rendered correct, but on second device with bigger screen and bigger webview, it doesn't fit.
I expected page to fit the second webview following white spaces, because page is fixed size and second device screen is bigger.
How to fix this?
Html had this line:
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0" />
It was the reason why setInitialScale() didn't work at first.

How to fit web page to webview's width when webview resizes (without reloading)

I have an HTML page and a full-screen Android webview. The HTML content is larger than the webview's visible area. I want to fit the HTML content to the width of webview.
What's really important is this: when the device's orientation changes, the webview will not reload, meaning it will just resize and the content would still fit to width.
One more thing: because the content has been scaled down, user can zoom it in to a maximum scale of 100%. When the content is zoomed and orientation changes, I want the content to fit-width again.
Edit 1: I can change meta tags in the head of HTML, but its content remains larger than the webview's visible area. I'm supporting Android 2.3 and later.
Edit 2: Thanks for the suggestion on responsive web design. I know what it is and I can do it. Problem is I cannot change much of the HTML content in this case.
TL;DR: How to always fit a larger HTML content to a Android webview's width as the webview resizes, without reloading the content. (I can change the webview, not much of the HTML.)
do following settings
webview.getSettings().setUseWideViewPort(true);
webview.getSettings().setLoadWithOverviewMode(true);
This may sound like a cop-out answer, but I think it depends on how you're building the rest of your site. Whenever I work on responsive sites, I use:
<meta name="viewport" content="width=device-width, initial-scale=1">
This will do two things: width=device-width will find the width of your device, and send styles from your CSS that match that size (you can set styles for specific sizes in your CSS, using media queries). Initial-scale=1 will make the site show up at 100% when it loads, but still give users the option to zoom in.
If your site is developed for a specific width, you could try using:
<meta name = "viewport" content = "width = 980 (or whatever the width you're designing for)">
This will just scale down your site to fit the device width. Nothing super special here, users will basically just be shown mini-desktop sites.
I'd recommend reading this Webdesign Tuts+ article. They explain the viewport meta tag well, with examples.
You need not change anything on Webview , all u need is Responsive
Html Page, If you are designer then that will solve ur issue or u can
post a part of ur Question with UI tag.
To built Responsive html pages u can visit : HERE
Result : You need to test on webview while creating your responsive
html page, default brower of android itself reflect that ur html page
is responsive or not.Once it will work in default brower in Android
device then it will work in any webview in android.
Testing : you can test ur responsive html page HERE
I would have to see the source of your HTML and CSS. You have to exclusively use % sizes and never use fixed width px sizes. Then, the user can change the size of the browser and it will dynamically resize. I also use % widths because of this. It also dynamically resizes if you use CTRL-MouseWheel (zoom).
Here's a tip for responsive web design, use positions instead of widths:
For example:
html
<div id="somediv">I'm just a div, just a regular div.</div>
css
#somediv {
left: 0; /*numeric value in pixels you would like this div to be from the left */
right: 0; /*same as above, except on the right */
height: 50px;
width: auto;
}
The div above will automatically resize based on screen width.

Android Browser resizes text automatically

I have a project that is displaying 16px text font at 0.5ems links on the iPhone perfectly fine.
However, when I switch to an Android browser, the text font enlarges itself and my positioning of the links are screwed.
My links are in a
<p><a>[Link]</a></p>
statement.
Is there any way to prevent the Android text from resizing itself? Or is there a better solution to this?
EDIT:
I just realised the android browser doesn't allow for auto scrolling as well. Why is this so? Aren't both the iPhone and Android browsers using webkits as its base? Why are they so different even though they use the same technology? Are there any extra attributes i should declare in CSS for it to work the same as the Safari counterpart?
I had a similar problem as well. I had a design that was designed specifically for the Retina display, but the retina display actually has a pixel density of 2, so a pixel isn't necessarily a pixel (non retina iphone pixel width: 320px, retina: 640px).
To fix that, I put this in the <head>: <meta name='viewport' content='width=device-width, initial-scale=.5, maximum-scale=.5'> so that a normal phone will scale as I expect, and the retina display would scale appropriately (half scale).
I'm not sure what kind of design you're using, but I'd play around with the initial-scale and maximum-scale, try both .5 and 1 and see what you get.
If you use pixels (px), it is related to the screen pixel density. An iPhone "retina" display would show text differently to your Android device.
This article covers the topic pretty well: http://kyleschaeffer.com/best-practices/css-font-size-em-vs-px-vs-pt-vs/
I found a setting that might help in another question, Font size rendering inconsistencies on an iPhone:
body {
-webkit-text-size-adjust: 100%;
}
An alternate value is described in another question, Font size issue with iPhone:
html {
-webkit-text-size-adjust: none; /* Prevent font scaling in landscape */
}
Seems like one of these might prevent the android browser from resizing. Hope this helps.
If you want to stop Android from auto-scaling your pixel values, you can try adding this to your viewport meta:
target-densitydpi=device-dpi
Here's a good reference on the same:
http://designbycode.tumblr.com/post/1127120282/pixel-perfect-android-web-ui

Categories

Resources