scaling factor for sw-XXXdp qualifier - android

is there any scaling factor for using in sw-XXXdp? i want my exactly look same in different screen sizes and densities.
for example for sw-480dp my value is 100dp what is it in sw-800dp? 100*?

Actually, sw-XXXdp is not a density qualifier, so you will not have any scaling taken in account, except if you combine it with a density qualifier (hdpi, xhdpi, etc).
As found on Android developer's website:
The smallest width qualifier specifies the smallest of the screen's two sides, regardless of the device's current orientation, so it's a simple way to specify the overall screen size available for your layout.
The smallest width qualifier (sw-XXXdp) is just here to make sure that the screen will have a minimum size for your layout. For instance, it's good to use sw-480dp if you have a content that should be at least 400dp wide or high, so you still have space to add margins and have a good look and feel.
In the end, to your question:
for example for sw-480dp my value is 100dp what is it in sw-800dp? 100*?
I would answer that you can follow proportional rules, so assuming you have 100dp as a baseline (mdpi) for a sw-480dp screen, you should have around 166dp for a sw-800dp screen and then adapt regarding the different densities.

Related

Android - Absolute unit of measurement

If I wanted to create something that is exactly one inch apart on every Android screen, I would use pixels correct? Inches and dp seem to scale to the individual size of the screen meaning on one device it could be one inch and on another it could be 1 1/4th.
Also, is there an easier way to do this besides finding how many pixels are in an inch and then adding the views with the correct margin pragmatically?
You would use density independent pixels. Also known as dip or just dp.
Dp ensure that things are nearly the same size on every screen. ("Nearly" because this is android, with a huge fragmentation, and custom roms, ...etc)
So one inch will be a varying amount of pixels on each screen. If you use pixels, things will be smaller on high resolution displays. So use dp and everything will be the correct size on the actual screens.
While using dp might be off by a pixel or two (might!), this is probably as good as it gets. Also, you should try not to create pixel perfect design with android—You will have a hard time with different screen sizes (and not just resolutions)
Generally speaking you should try and follow the material design guidelines by google for android, and rather use multiples of 8dp for sizes, instead of trying to find out how much an inch is.
Density-independent pixels (dp) is the unit of measure which appears to be the same actual length on any device.
Try this: create a view whose width is 100dp and run it on a hdpi device. Measure the width of the view using a ruler or something. Then run the app on a mdpi device and measure the width. You will find that the two widths are about the same.
This means that, just as its name suggests, the actual length of a dp is independent of the screen density.
If you used pixels, however, the actual length will vary from screen density to screen density. If the screen is denser, 100px will appear shorter. If the screen is less dense, 100px will appear longer.
Get it?
tl;dr: Just use dp!

Wrap_contents or DP for ImageView

I see some people user the exact dp measurements for Imageview width and height in their layout while some others use wrap_contant.
Wrap_content would take the image size and display it accordingly. So if it is 60px by 60px then it will look smaller on high density screen and larger on low density screen.
While using the exact dp measurements lets say 60 dp, will make it look of the same size on all the screens.
As a result, shouldn't we be using the exact measurements all the time and not wrap_content? Am I missing something here
Thanks
I think if you use wrap_content, then the system will choose the resource from the appropriate resource folder depending on the screen density (mdpi, hdpi, xhdpi, etc) and will use the px dimension of that resource. Since the screen density resource folders (mdpi, hdpi, etc) can each apply to various screen densities (ie, mdpi is ~160dpi, but can be a bit less or a bit more before hitting the next density), this means that the image may change size slightly on different screens. If you specify the actual dp value for height and width, then you ensure the image will scale to maintain the same physical size on all devices.
Sometimes wrap_content is too small than what you want, or too big than what you want
so you can give exact measurements
If you want to make sure your exact measurements support multiple screen sizes, you can put them inside a dimens file which then loads according to the correct screen size
look into Support Multiple Screen Sizes
if for example you create a folder calld "values-sw600dp"
and put a dimen file in it, and have a property
<dimen name="imageSizeWidth">60dp</dimen>
And your image will be defined as follows
<ImageView
android:layout_width="#dimen/imageSizeWidth"
android:layout_height="#dimen/imageSizeWidth"
/>
Then it will be loaded, if the device matches the description "at least 600dp scree width"
this is providing there are other values folders in your resources.
If you don't have any other values folders, then this will be loaded by default

The measurement independent of the LDPI,MDPI,HDPI

Can any one tell me whether is there any unit in android such that if I set the value of a margin/padding with a value,then that will be automatically adjusted in the other type of devices.
For example- If I set the margin/padding as 10dip based on HDPI then the alignment wont be OK in mdpi or ldpi with the same code.
I seached about this but couldnt find any solution.
MDPI, LDPI, HDPI etc... Specifies the resolution (pixel density) of a device. It Has nothing to do with the physical size of the screen. You can have small phones with an XHDPI screen, and big tablets with LDPI and the other way around.
If you want to size items relative to the size of the device, you can raise the LayoutWeight of the widgets. The left over space on the screen is distributed over the widgets with nonzero weight.
First of all i suggest you to use 8dp as common padding/margin between your views it is standard and now as you said you need a measure that automatically resize the space you mentioned according to the screen size. right? they you should consider using small/normal/large/xlarge instead of ldpi/hdpi. for more information i suggest you go through this guidelines http://developer.android.com/guide/practices/screens_support.html

When designing a UI interface for MDPI and HDPI ANdroid how do i beat the height issue?

Having designed an interface for HDPI in Fireworks (480x800) and now moving it over ready for an MDPI version (320x480) i've come across an issue
Proportionally, the HDPI screen is slightly taller than the MDPI screen.
I know my images will resize, but even still am losing some space height wise
Evyerthing fits on screen beautifully on HDPI version....but now its resized down to MDPI the smaller proportion in height means i'm more stuck for space.
How does one avoid this issue?
I asked the developer if the space between elements can be altered for the MDPI version (eg, on a screen with 8 text fields.... the space between the fields is shortened), he said it will work on percentage of the screen etc.....that's all ok...problem is that
A 480x800 screen -- if this is downsized (proportionally width and height) to a width of 320, the height ends up as 533, not 480.
Therefore i lose 53 pixels in height.
Have I got confused? How do i sort this out?
Much thanks
First of all
Proportionally, the HDPI screen is slightly taller than the MDPI screen.
You can't say taller it or not. Density doesn't define resolution.
Evyerthing fits on screen beautifully on HDPI version....but now its resized down to MDPI the smaller proportion in height means i'm more stuck for space.
So, as I said - MDPI also doesn't means that your screen resolution is less than HDPI screen resolution. For example, I have an tablet with 1280x800 resolution and MDPI screen. Get it?
Looks like it's better for you to provide different layouts for different sizes of devices (small, medium, large, xlarge).
its better use layout weight and also make sure you use desipixel dp instead of px everywhere while designing your ui in xml. The best way to practice while designing ui is to ensure that the application will work and look fine regard less of the screen size
For more information on layout weight check this link
Use a ScrollView. However, I wouldn't recommend designing a layout for a fixed screen size, or even for a fixed ratio.

Android multiple screen support

I am confused about android's multiple screen support. http://developer.android.com/guide/practices/screens_support.html I read this article, but still something is not clear for me.
I used dp instead of px in my layout
I put high, medium, low version's of an image to drawable directories.
I made this changes according to this article. But in some densities, there is still problem although some of them work very well.
The question is what is the exact width and height in dp units for variety of android screen types. if it is changeable, what is the difference between px?
px is changeable, dp is changeable too??? what is the difference??
if changeable, should I change the view's width and height by code on Create function or create seperate layouts for each screen dentisies? Please give a way to understand this...
Thanks in advance..
px are not changeable. dps or dips are.
To calculate how many px your object specified in dps will be use the formula below:
The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
px is a fixed measure. This means that if 100px on a small screen take up 1/2 of the screen, it will take up much less on a large screen. dp = density (independent) pixels, is based on the densitity of the device. So if you specify a width to 50dp on a small screen, it will expand on a large screen. Note that dp is not an insurance of layout compability on all devices, since devices have different aspect ratios. To build a perfect layout, that looks exactly the same on all devices, you must use more techniques. Linearlayout allows you to assign weights. Look into that. http://developerlife.com/tutorials/?p=312

Categories

Resources