what "font size" measurement should i use in titanium? - android

Given that it is for both android and ios devices, and given that i'd like the screens to be pretty consistent across different screen sizes/resolutions?
I'm using font-size right now, but there is a massive disparity between what the android emulator shows and what an actual android device displays.

Try this, you can you without any measurement (dpi or px). this is working. bye the way you also you with (dpi or px) on your requirement.
var name = Ti.UI.createLabel({
backgroundColor : "#e3e3e3",
text : data_ary[z].name,
height : "40",
left : "70",
width : "auto",
color : "#2c2c2c",
font : {fontSize : 18,fontWeight: "bold"},
});

so my question (now fixed) was a bit... wrong? I noted that i was using fontSize without really specifying what that meant.
I really should have noted that i was using fontSize without any units of size. Following on from Richard's suggestion, i'm using the units "sp", so for example:
font: {fontSize: '14sp'}

Related

Android layout too big on some devices

My apps layout looks fine on my device and any device I tested it so far. The layout has some seekbars with a fixed dp width and a textview beside it.
But now I saw a screenshot from another device and the text is cut off, because the graphics appear so big.
This surprises me because they are normally fittingly resized depending on the density bucket (designed for xxhdpi) and I did never see this problem before. Maybe the device is just on the edge of a density bucket? Is there a certain dp width that I shouldn't exceed?
I don't know what would cause this problem.
You have to change the border margin in dimens.xml
You can do certain things to solve this.
As #yashetty29 suggested
If its only the text problem you can forcefully set that text size in dp and not sp. Many users makes device font size larger ( like my dad :p ) that makes weird looking UI.
or you can use this library. It may help you.
SSP: for text (sp values) -> https://github.com/intuit/ssp
SDP: for text (dp values) -> https://github.com/intuit/sdp

Why I should not hard code sizes such as width,height,fontSize,padd,margin for responsive design in react native?

I thought like if I give width: 10, it will look the same in all devices since it occupied the same amount of area (because in 160dpi, 10dp = 10px, 320dpi 10dp = 20px but occupies same area in an inch)).I think my understanding is wrong. Share your thoughts on Responsive design and how to approach responsive font size as well. Thanks.
Ive been through this phase , and thought similiar , but i was wrong. Sizes are different on different mobile so the best appraoch would be to actually calculate and make it in a percentage.
react-native-responsive this is the library i use for actually making my app responsive and it worked out well. All you need is actually know your testing device height and width , suppose its 360*640.
Now you want to apply height of 200 , so basically you do 200/640 , i.e 31.25 ,
so in your view or whatever image you want you can add height by height:hp('31.25%'), and thats it, it adjust accordingly to devices.
And if you dont want to use any library , you can use Dimensions of react native.
import {Dimensions} from 'react-native';
var {deviceheight, devicewidth} = Dimensions.get('window');
Now similiar approach , you now need to know resolution of your testing device and if its 360 * 640 , then you can do the same , just here suppose again height is 200 , then you have to do height:0.3125*deviceheight
Hope it helps. feel free for doubts
In width: 10,, 10 is equivalent to 10 units. So in such cases, it will always set the with to 10 pixels, no matter which device/screen you use.
Instead, you can use percentage or relative measurements so that it can adapt to different devices, therefore, making your elements 'responsive'

fancyBox: Scale Issue on Device / Orientation Rotate

When using fancyBox, whether its an image or an iFrame (YouTube), and open this on a mobile device and then rotate (landscape to portrait or vice versa), fancyBox doesn't scale or fit to width of device window?
fancyBox Options:
$(document).ready(function() {
$(".fancybox").fancybox({
helpers : {
media: true,
title: null
},
width : 800,
height : 450,
aspectRatio : true,
scrolling : 'no',
openEffect : 'fade',
closeEffect : 'fade'
});
});
Device: SAM GALXY S3
OS: ANDROID 4.2
Browser: FF / CHRME / DOLPHIN
fancyBox version: 2.1.5 PACK
p.s. this is happening also on the examples, both versions 2 and beta! :/
Your code appears to be setting a static width and height value for your fancy box. That's not a bad thing to do, but it does explain why your fancybox is not fitting the device screen: mobile devices tend to be less than 800px in width.
To fix this, you can easily use css styles to set max-widths for fancybox classes "fancybox-wrap" and "fancybox-inner".
Example:
.fancybox-wrap{max-width: 95%!important;}
.fancybox-inner {max-width: 100%!important;}
These rules use !important because they need to be able to overwrite the html width/height set by the fancybox options.
You can easily set the same styles using a jquery function to set css styles in fancybox's afterLoad option (though there may be more efficient methods to use than afterLoad, it should still get the job done.)

Which emulator should I use for a Huawei Y300 and Y530?

I am trying to emulate a Huawei Y530. According to this site, it has the following specifications:
Screen: 480 x 854 pixels, 4.5 inches (~218 ppi pixel density)
This is what my WEB APP looks like on the actual device:
And this is what it looks like on a emulator, with the following specification:
Target: Android 4.3 - API Level 18
Device: 4" WVGA (Nexus S) (480x800 hdpi)
I know there is a difference in the height of the two devices, but still I believe that the emulator should show something similar to what the actual device is showing.
I tried to find the innerWidth and innerHeight of the real device with the following code:
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
alert (viewportwidth);
alert(viewportheight);
The result is width: 320px and height: 544px
The innerWidth on the emualtor is: 480px and the innerHeight: 756px
Since the real device had a width of 320px, i tried using an emulator with the following specs:
Screen: 3.2" QVGA (ADP2) (320 x 480 mdpi)
With the following result:
You can always create a new emulator if the app will be developed only for this particular phone. The image attached emulates the exact properties of the Huawei Ascend Y530 phone.
Alternatively, if the app is being developed for different phone having different screen sizes, I would take a look at the xml file for the layout. Take note of the following attributes, like placing form widgets in relation to other widgets. For example: android:layout_toRightOf="#+id/ukFlag" for the Danish flag. There are actually several layout parameters you can paly around with until you get the right layout:
Layout_toLeftOf
Layout_toRightOf
Layout_above
Layout_below
You can also setup the positioning of the widget, to be either left_based, right_based or centred.
Hope this would help you better: Android Layouts
Without knowing too much in how you have done your application, it seems you are using fixed units like pixels to specify size. As this project is a web app, maybe you should consider to use what is called a Responsive Design approach. In that way your content can adjust to whatever size the screen is.
I'll let you a couple of useful articles to learn more about this:
Responsive Web Design in Wikipedia
Responsive Design Presentation
Responsive Design Examples

Use Ti.UI.SIZE in dp instead of pixels in Titanium

I want to use Ti.UI.SIZE in dp (density-independent pixel) instead of pixels to support all android different resolutions, I have an imageView that gets its image from a url, so I don't know what is the width or height of the image and therefore I set them to Ti.UI.SIZE, it works well on iphone but the problem is in android.
So, is there anyway to use Ti.UI.SIZE in dp not in pixels ?
Thanks in advance !
A good solution is to make 'dp' your default unit instead of pixels.
Just open tiapp.xml the string 'system' or 'px' to 'dp'...
<property name="ti.ui.defaultunit" type="string">system</property>
change it to
<property name="ti.ui.defaultunit" type="string">dp</property>

Categories

Resources