Supporting different sizes and densities imageview - android

I have a viewpager with imageviews and I have set it like this:
mViewPager.setPageMargin((int) getActivity().getResources().getDimension(R.dimen.view_pager_margin));
<dimen name="view_pager_margin">-250dp</dimen>
Now, I've created the following dimens files:
But, when I start Nexus 5X and Nexus 6P emulators they both share the dimens.xml(xxhdpi) file and the images don't look good on both. What would be the best approach so my images can look as they are supposed to on every device?

According to https://design.google.com/devices/, the 5X and 6P both have dimensions of 411 dp x 731 dp. However, the 5X is an xxhdpi device, whereas the 6P is an xxxhdpi device, so they're actually using different dimens.xml files.
I would recommend defining your dimens.xml based on actual screen dimensions rather than screen density. For example, a dimens-w400dp.xml would apply to both devices.
https://developer.android.com/guide/practices/screens_support.html#NewQualifiers

Related

How to target font sizes for different screen densities?

I am developing an android tablet application. To support different screen sizes I am using resource qualifiers
sw600dp - Nexus 7 like screens
sw768dp - Nexus 9 sized screens
sw800dp - Nexus 10 sized screens
sw840dp - Pixel C Sized screens
Now I came across a situation where the same 10 inch screen has different densities.
Nexus 10 #density 2.0
Kindle Fire 10 #density 1.5
Both these devices are fetching the values from the sw800dp folder. But in nexus 10 the font sizes are normal and on Kindle Fire 10 HD the font sizes are very large.
What's the best way to target these two types of screens?
Also am I following the correct method in targeting multiple screen sizes?
For Nexus 10 font size, create res folder. by default is portrait.
values-sw720dp-land
Happy coding!!
Make folders like this
values // default values
values-sw400dp
values-sw600dp
values-sw800dp
create dimen file in each folder for diffrent screen wise size

Android - Dynamic text scaling for same dpi but different screen size

In my app I create multiple TextViews dynamically and the text size for each one I derive from the value stored in dimens.xml under values folder. On one hand I have the Nexus 4 and on the other hand I have Nexus 10. Both have the same "xhdpi" density bucket but one has the screen size of 4.7 inches and other has a screen size of 10.05 inches. I can have the same value for textsize due to their same density bucket but the text appearing fine on Nexus 4 appears too small on Nexus 10. How can I have my text appear appropriately large on such devices ? Let me know if any files need to be included.
In your dimens.xml file use sp instead of dp.
Before
<dimen name="text_size">80dp</dimen>
After
<dimen name="text_size">80sp</dimen>
Create values-sw600dp and values-sw720dp and check in which one your tablet falls in. Set the dimension larger for the same key name in values-sw600dp and values-sw720dp based on your requirement.
After doing a lot more research I found out you can use both size and resolution specifiers together. I simply used values-xlarge-mdpi for Nexus 10 and values-large-mdpi for Nexus 4.

Android : Screen Size

I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.

Android Not Respecting my res folders

I'm having some issues in an App that I'm developping in Android:
We are creating an app with support for multiple screens, going from an Samsung Galaxy Ace to a Samsung Galaxy Tab 2 10.1, Supporting small, medium, large and x-large screens, but, somehow Android is not respecting my layout-xxxx folders. In Eclipse visual layout editor, when I Change the Screen it moves me to the correct folder, for representing that layout. But, In Android, Emulator or Real Device, the Layouts in their folder aren't displayed the correct way.
My folder structure is like the ones, mentioned at Android Developer:
res/layout-xxxx
res/values-xxxx
I've also read that since Android Honeycomb, somethings changed, the small,large,xlarge qualifiers became depecrated. So We created folders using layout-swdp, and we thought that would be the Solution for Devices with honeycomb +. But, soon we realized that this didn't work.
So, Is there a exact way to do this?. To make Android respect or force, these folders?.
Also, in Android 2.2 when using Dimens, the App didn't start. It tells that there's no dimen 0x01. Thank you In Advance.
Personaly I would use Screen pixel density (dpi) for each layout.
That is:
ldpi: Low-density screens; approximately 120dpi.
mdpi: Medium-density (on traditional HVGA) screens; approximately 160dpi.
hdpi: High-density screens; approximately 240dpi.
xhdpi: Extra high-density screens; approximately 320dpi.
Added in API Level 8
See http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
The folder should be:
values > Standard phone screen
values-sw600dp > 7" phone/tablet screen
values-sw720dp > 10" tablet
You have to initialize <dimen name="myvariable"></dimen> in the XML file within those folders and call inside your XML.
Example:
<Button
android:id="#+id/btnHome"
android:layout_width="#dimen/myvariable"
android:layout_height="#dimen/myvariable"
android:text=""
android:background="#drawable/homebutton" />
And it will resize based on the screen size.
I am working on my app and that ensures the size is same across all three screen.

Can't get drawables resolution right for Android tablets

I use .png as a background for a custom button that I declare in XML like this
android:background="#drawable/samplepng"
But I can't get the resolution right for tablet screens :
For example, my ressource is a 200x200 pixels .png (initially designed for iOS and retina)
I place a 100x100 px version in the drawable-mdpi folder and a 200x200 px version in the drawable-xhdpi folder.
I also need to have a layout for a typical 320x480 screen in the layout folder and another layout for 10" tablets in the layout-xlarge folder.
The size of the button is 100x100 dp in the normal layout and 200x200 dp for xlarge layout, so that it looks right.
With the Android emulator, a 10" tablet uses mdpi ressources and xlarge layout.
As a result, the button background is drawn with a scaled version of the 100x100 image which looks very blurry, as opposed to the crisp 200x200 original image.
If I don't use a mdpi ressource, it looks blurry just as well.
Am I doing something wrong ? is it only an emulator problem and it looks nice on a real device ?
Please help, I read 10 times google's doc but can't find an answer.
If you don't launch the emulator with 'Scale display to real size' checked, then it will always use mdpi drawables.
See here for more.
Your issue might be in the android version your targeting. Try switching the emulator to android 3.0 and 3.1.

Categories

Resources