I am trying to load external webpages into a webview that is smaller than the device. This is an example:
var window = Titanium.UI.createWindow();
var webview = Titanium.UI.createWebView();
webview.setWidth(320)
webview.setUrl('http://www.bostonglobe.com')
Ti.API.info('webview width = ' + webview.width);
window.add(webview);
window.open();
You can see the webview scrolls horizontally, acting like a its the same width of the device, not 320 as specified.
Any help to make this work would be appreciated.
This is actually very easy to do and is built in to Titanium for all platforms. Just use the scalesPageToFit property of the WebView, this has been around since Titanium version 0.8 so its quite stable.
var self = Ti.UI.createView({
backgroundColor : '#ff0000'
});
var webView = Ti.UI.createWebView({
url : 'http://whatsmy.browsersize.com',
scalesPageToFit : true,
width : 280
});
self.add(webView);
Note the platform difference though:
"On iOS, setting this to true sets the initial zoom level to show the entire page, and enables the user to zoom the web view in and out. Setting this to false prevents the user from zooming the web view."
"On Android, only controls the initial zoom level."
Also note that their is a difference between pixels, and points, as every screen has different pixel density. Here is a screenshot showing this works, note the surrounding red background:
Thise screenshot was taken from a vanilla project using the "Default Window" template from Titanium Studio. All I did was replace the "ui/common/FirstView.js" file with this gist.
It is possible if you make your WebView very small that it wont show the content (as many websites specify a minimum zoom scale) so in that instance I would suggest using a transform like this:
var webView = Ti.UI.createWebView({
url : 'http://whatsmy.browsersize.com',
scalesPageToFit : true,
width : 280,
transform : Ti.UI.create2DMatrix().scale(0.5, 0.5)
});
All this does is take the previous view and half-size it.
Of course, you will have to calculate your own uniform scaling factor, but that should be straightforward depending on your requirements and platform target. Here is a screenshot of the scaled result.
Using a combination of these methods you definitely have the tools needed to solve this problem. Good luck!
try doing it this way instead and see if you get better results:
var webview = Titanium.UI.createWebView({
width:320,
url:'http://bostonglobe.com'
});
Another point to consider is that the page you're loading probably isn't mobile friendly. Apple's web view control is deciding to show it at a scaled rate to make it fit. In the case of whatsmy.browsersize.com, it's telling you the scaled size of the web page, not the control size of the web view.
You most likely want to change the width and initial scale of the web page's viewport.
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=3.0;" />
EDIT: For third party sites, after the page loads, you can force it to scale via JavaScript. If you don't want to see the initial unscaled page, hide the web view until has scaled down.
webView.evalJS('document.body.style.zoom = 1.5;');
Related
I have an owl carousel with cards in my project. It's my first time using it. I've set up to be one card in viewport while screen is small but the arrows are still too big and not fitting the screen nicely. Is there any possibility to change that? sorry for asking but as I wrote earlier I'm just learning all the web dev stuff.
check if this thing is in your css.. reducing the font size would change the size of the arrows
.owl-nav i {
font-size: 52px;
}
I've noticed that when I add an HTML app in Rally/Agile Central, the height doesn't fit/adjust within the browser windows. This means that a vertical scrollbar is always added.
I'm using Chrome and Firebox, but they both have this problem.
Is there a way to limit the height of the custom app?E.g., to (height - 25) so that the browser scroll bar is not necessary?
Can you share some of your code? It might help in diagnosing what's going on. A couple ideas though...
Are you using a layout for your app? This often can help with scrollbar issues.
This guide may be helpful for learning to work with layouts: https://docs.ca.com/ca-agile-central/saas/apps/2.1/doc/#!/guide/layouts
If you're just using auto layout (the default, if you didn't explicitly specify one) then you can also try adding autoScroll: false to your app's config. Note this may cause your content to be clipped if you do actually need a scrollbar though.
Here is an examle with the std list app - and it's the same whether there is anything to show or not.
I'm thinking that it is the HTML app that doesn't take into account that there is a page title, in this case "*test layout scroll bars" - and somehow uses the "full height" = the entire frame (I'm not an html/css expert)
I am finding it difficult to set the right look and feel of a CN1 Slider control. Essentially i want it to look like the one in the CN1 Default Demo of the Theme window, and have it with the Thumb image to allow the user to set the scroll.
But when i code it up as per online examples, it comes out skinny on the simulator (as below)
...but doesn't display the line at all on the actual iphone device.
When i start messing with the methods, such as 'getSliderEmptyUnselectedStyle()' then this makes the background show and can see the progress but its tall and i cannot seem to shrink it.
Container container = new Container(new FlowLayout());
container.getAllStyles().setBgTransparency(255);
container.getAllStyles().setBgColor(0xffffff);
Slider slider = new Slider();
// slider.getAllStyles().setFgColor(0);
// slider.getAllStyles().setMarginLeft(0);
// slider.getSliderEmptyUnselectedStyle().setBgTransparency(255);
// slider.getSliderFullUnselectedStyle().setBgTransparency(255);
// slider.getSliderEmptySelectedStyle().setBgTransparency(255);
// slider.getSliderFullSelectedStyle().setBgTransparency(255);
// slider.getSliderEmptyUnselectedStyle().setBgColor(0xffffff);
// slider.getSliderFullUnselectedStyle().setBgColor(0x42B72A);
// slider.getSliderEmptySelectedStyle().setBgColor(0xffffff);
// slider.getSliderFullSelectedStyle().setBgColor(0x42B72A);
Style sliderStyle = UIManager.getInstance().getComponentStyle("Label");
sliderStyle.setFgColor(0);
slider.setThumbImage(
FontImage.createMaterial(FontImage.MATERIAL_RADIO_BUTTON_CHECKED, sliderStyle, 4).toImage());
slider.setMinValue(0);
slider.setIncrements(25);
slider.setProgress(entity.getCompletion_pct());
slider.setEditable(true);
container.add(slider);
return container;
How can i get it pretty much to the CN1 example?
Thanks
The slider in the example used a 9-piece border or a 3-piece border both of which have a fixed minimum height/width. This minimal height is applied to the way the slider is rendered.
Your code can be made thicker with padding but it will create a problem when you add a thumb. Once you add the thumb it will increase the overall size and make the entire height of the thumb have that background. So you need to style this via the designer and for this specific case you would want to use an image border that is carefully measured to align with the thumb image.
Also notice you used getAllStyles() which is wrong. Slider is a special case and uses the Slider and SliderFull UIID so effectively the component has two UIID's and two separate sets of Style objects.
I'm used to using Titanium.Platform.displayCaps.platformWidth all over my app to get the width of the window.
But with SplitView on the iPad Titanium.Platform.displayCaps.platformWidth still returns the total screen size of the iPad (as it probably should).
How can I determine the actual available screen width for the app while using SplitView?
I don't mean SplitWindow BTW. This is in regards to SplitView where you can line up two different apps next to each other on the iPad
Thank you!
you can get the width your uiElement using postLayout event
var uiWidth;
myElement.addEventListener('postlayout', postlayout);
function postlayout(e){
uiWidth = e.source.rect.height;
myElement.removeEventListener('postlayout', postlayout);
}
An easy way to determine how wide a certain view is, is to use toImage() on the UI element, and then get the size.
So... when you do
console.log($.myWindow.toImage().rect.width);
You should get the width of the window. Which should be the width allocated to your app.
The WP responsive theme I'm working on:
http://www.wpexplorer.me/tetris/
I use Firebug for Firefox browser addon thingy to make changes before messing with the actual files. So if you have it or something similar, you will see that by adding position:fixed; to the #header section the header width shrinks well more than half its original size and the navigation menu is jacked up within the new shrunken space.
I have added other snippets of coding to the #header section like width:100%;, width:959px; and other percentages and pixels, which messes up the layout; especially when you resize the window down to what you would consider to be for a tablet and a mobile device - it's all out of whack. I can't get the sticky header for this theme to function or do right. Oh, I've also added z-index:200; to the #header section and margin:160px 0; to #main-content; these don't give me issues.
Adding the width: ; code to the #main-content doesn't seem to help either (which I read somewhere online that this was where the width code goes).
Anyway, does anyone know what code I need to make the header of this theme scroll up until it gets to the top of the page where it becomes sticky/static/fixed/on top (whatever the real term for it is) at all times? And, can you get it to work with the layout being in tact when the window is resized all the way down to the size of a mobile device?
Thanks.
This should work
#header-wrap{position:fixed;top:0;z-index:999;}
#pre-header{margin:20px 0 15px;width:960px;}
#main-content{margin:215px 0 30px;}
The position is fixed at the top using 0 with a z-index:999 you then need to set the width of the inner container pre-header 960px to match the rest.
You will need to setup the media queries for the other sizes you have setup. Easy, and Enjoy.
If you want the menu itself and not the social icons to become the top fixed bar without the social icons then you want to make a jquery scroll CSS change so that the #header becomes the fixed position.
It working with fixed header and social:
An illustration of it working without the social bar using a Jquery Scroll CSS change:
This is the way I would do it, I would move the menu down, and add the social icons to the menu itself. (Below is a screenshot of what I mean, the social icons are reduced to 75%)
PS. The social icons stand out to much so I would add a CSS3 Greyscale, and when the visitor hovers over them it turns on the color with a transition effect.
Hope this helps ;)