I want setup different dimen-values for different resolution(dp) devices, how ?
just in my dimens.xml
<resources>
<!-- for 1280x720 dp ,Default screen margins, per the Android Design guidelines. -->
<dimen name="image_thumbnail_size">200dp</dimen>
<dimen name="image_thumbnail_spacing">2dp</dimen>
<dimen name="image_detail_pager_margin">160dp</dimen>
<dimen name="activity_horizontal_margin">80dp</dimen>
<dimen name="activity_vertical_margin">100dp</dimen>
<!-- for 640x360 dp -->
<!--
<dimen name="image_thumbnail_size">100dp</dimen>
<dimen name="image_thumbnail_spacing">2dp</dimen>
<dimen name="image_detail_pager_margin">80dp</dimen>
<dimen name="activity_horizontal_margin">40dp</dimen>
<dimen name="activity_vertical_margin">30dp</dimen>
-->
add:
I have two devices, the resolution is 1280x720 ,but my phone dp is 640x360 , and another is 1280x720
Create seperate values folders, each with a different suffex. Some examples:
values-normal (for phone versions)
values-large (for 7" tablets)
values-xlarge (for large tablets)
Place a dimensions.xml file in each of these folders, in each one, specify different values for each variable.
Hope this helps.
Sorry to get this to you late but you can use the same folder combinations that you use for drawables with the values folder. Here is an example
values-ldpi/dimens.xml
values-hdpi/dimens.xml
values-xhdpi/dimens.xml
Related
I am using multi support value for dimension , I have given value like this
I have attached screen shot dimen folder please check this
I have make the value folder like
value
dimen.xml
<dimen name="padding_1">1dp</dimen>
and
values-sw320dp-hdpi
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw320dp-xhdpi
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw320dp-xxhdpi
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw360dp
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw480dp
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw600dp
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
values-sw720dp
dminen.xml
<dimen name="padding_1">what padding should I give</dimen>
My question is that what padding dimension should I give so I can support to different different device, like how to find the 1dp for every value folder.
I have go through with this link
https://developer.android.com/training/basics/supporting-devices/screens.html
but not understand clearly. I have gone through the Dimenify plugin as well but not getting clear solution.
Edit
I wanted to know is there any way to put exact dimension in all value bucket or
any dp converter which convert exact dimension for all value bucket in android
values folders to create
values-sw320dp,
values-sw480dp,
values-sw600dp,
values-sw720dp. You should create dimens.xml in all the values folders.
values-sw360dp
dimens.xml
<dimen name="padding_1">5dp</dimen>
values-sw480dp
dimens.xml
<dimen name="padding_1">8dp</dimen>
values-sw600dp
dimens.xml
<dimen name="padding_1">10dp</dimen>
values-sw720dp
dminen.xml
<dimen name="padding_1">13dp</dimen>
Based on your requirement you can give padding or any dimen values. As you
given, you should give same name for dimen in all the folders. Android will
automatically pick the dimen value based on your screen size.
A few tips to help you go with your answer.
The dp metric lets you define consistent sizes across device densities.
This would typically mean they look the exact same size on a majority of devices.
While giving a fixed width works for a few of the cases, visual appeal truly lies in the fact that you can scale down the size of your UI on smaller devices and scale it up on higher devices. You need to start using android's bucketing feature that pulls out different resources based on the device config with the same qualifying name.
Lets say you may choose for eg. to have margins
a margin_normal maybe visually perfect at 16dp for xxhdpi, but you see that 18dp works for xxxhdpi whereas 14dp works for xhdpi device.
These are subjective values but rest assured scale factors are a good approximation to this rule.
Dimenify deals with this conversion automatically but you need to provide the scale factors by trial and error and as a one time effort.
I am a bit confused how android decides what resources to choose. I have the following folders with the following files:
--
|-values
|-dimens.xml
|-values-hdpi
|-dimens.xml
|-values-land
|-dimens.xml
And the files content is the following:
First:
<resources>
<dimen name="data_dimen1">1dp</dimen>
<dimen name="data_dimen2">1dp</dimen>
</resources>
Second:
<resources>
<dimen name="data_dimen1">2dp</dimen>
</resources>
Third:
<resources>
<dimen name="data_dimen2">4dp</dimen>
</resources>
I have a device HDPI and in landscape. What will be data_dimen2 and data_dimen1 values?
data_dimen1 will be used. because values-land is for mdpi devices.
I recently ran some testing on the AWS device farm and was shocked to find that my text sizes are not scaling appropriately.
Currently, I have different folders for my text sizes:
values
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="center_indentation">80dp</dimen>
<dimen name="poll_question_text_size">14dp</dimen>
<dimen name="margin_left">80dp</dimen>
<dimen name="margin_bottom">8dp</dimen>
<dimen name="radio_button_answer_text_size">12dp</dimen>
<dimen name="answer_label_text_size">6dp</dimen>
<dimen name="answer_value_label_text_size">8dp</dimen>
<dimen name="vote_count_label_text_size">11dp</dimen>
values-sw600dp
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="center_indentation">80dp</dimen>
<dimen name="poll_question_text_size">22dp</dimen>
<dimen name="margin_left">160dp</dimen>
<dimen name="radio_button_answer_text_size">14dp</dimen>
<dimen name="margin_bottom">16dp</dimen>
<dimen name="answer_label_text_size">9dp</dimen>
<dimen name="answer_value_label_text_size">10dp</dimen>
<dimen name="vote_count_label_text_size">13dp</dimen>
values-sw720dp
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
<dimen name="center_indentation">80dp</dimen>
<dimen name="poll_question_text_size">30dp</dimen>
<dimen name="margin_left">185dp</dimen>
<dimen name="margin_bottom">20dp</dimen>
<dimen name="radio_button_answer_text_size">18dp</dimen>
<dimen name="answer_label_text_size">10dp</dimen>
<dimen name="answer_value_label_text_size">12dp</dimen>
<dimen name="vote_count_label_text_size">14dp</dimen>
In each folder, I create a dimens.xml file that I used to pull the appropriate text size for a given screen.
I went to the device metrics website located here and found was specifically looking at the Google Nexus 5. It appears that the Nexus 5, after I run my emulator, is pulling from my sw600dp folder. I am not sure why, and it is generating a text size that I would hope to see on a 7" tablet and not a 4.5" handheld device.
I have read countless posts on StackOverflow but cannot find any way to properly account for all devices. I understand that there are 6", 7", 8", 9", and 10" devices, and I want to ensure that I am accounting for each size.
Here is how my text looked for my Google Nexus 5, note I am referring to the radio_button_ansewr_text_size item:
When specifying text size, always use sp:
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp" />
or
<dimen name="text_size">13sp</dimen>
http://developer.android.com/training/multiscreen/screendensities.html
If you need to set text sizes in java code, do it this way:
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
I'm trying to decrease the text size of a textview depending on the device the app runs. However I can't make it work.
I created the folder values-sw320dp (also tried values-w320dp) and put inside the dimens.xml file
<resources>
<dimen name="text_size">25sp</dimen>
</resources>
and my values/dimens.xml file contains
<dimen name="text_size">18sp</dimen>
What I expect is to load the app in Nexus One (emulator), which is 482 x 320 dp, and get the text size 18sp. However I get text size 25sp.
Does anyone know what is happening?
Thank you
Create folder as values-hdpi
dimens.xml for values-hdpi
<resources>
<dimen name="text_size">18sp</dimen>
</resources>
And Create folder as values-xhdpi
dimens.xml for values-xhdpi
<resources>
<dimen name="text_size">25sp</dimen>
</resources>
And use like this-
android:textSize="#dimen/text_size"
I use values-hdpi, values-mdpi, values-ldpi, values-xlarge
Create folder as values-sw600dp and values-sw720dp in res folder.
dimens.xml for values-sw600dp
<resources>
<dimen name="text_size">4sp</dimen>
</resources>
dimens.xml for values-sw720dp
<resources>
<dimen name="text_size">6sp</dimen>
</resources>
Nexus One has dimension 480 x 800, so try
values-sw360dp
I am having an issue with scaling Android across multiple screens. According to the documentation Android OS will assume your dimens.xml is created for mdpi and scale accordingly for hdpi, xhdpi, etc...
However, I am not able to see this work. If I have a folder for values-hdpi my SGS4 looks fine with the 1.5 scale ratio applied from the dimens.xml file located in the values-hdpi. However, whenever I remove the values-hdpi folder from the project to allow Android OS to scale it up to hdpi, the SGS4 just runs mdpi values. I'm not sure what I'm doing wrong.
Android Manifest:
<!-- Screen Support -->
<supports-screens android:resizeable="true"
android:smallScreens="false"
android:normalScreens="true"
android:largeScreens="true"
android:anyDensity="true"/>
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="15"/>
Folder structure includes
values
values-es
values-fr
values-sw600dp
values has the mdpi values stored in the dimens.xml file all done in dp and sp.
dimens.xml:
(NOTE*) Whenever I tried to add the xml snippet from the dimens.xml it kept formatting it funny and removing all the dimen name= stuff and just lists out the dp and sp used in it. Not sure why.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="center_text_margin_right">20dp</dimen>
<dimen name="answer_row_top_padding">7dp</dimen>
<dimen name="answer_row_bottom_padding">7dp</dimen>
<dimen name="answer_number_text_size">12sp</dimen>
<dimen name="answer_left_margin_from_answer_number">18dp</dimen>
<dimen name="answer_text_size">12sp</dimen>
<dimen name="answer_points_right_margin">20dp</dimen>
<dimen name="answer_points_left_margin">18dp</dimen>
<dimen name="answer_number_left_margin">60dp</dimen>
<dimen name="center_text_size">12sp</dimen>
<dimen name="center_text_margin_left">20dp</dimen>
<dimen name="center_text_margin_right">20dp</dimen>
<dimen name="answer_title_height">28dp</dimen>
<dimen name="round_circle_margin_left">6dp</dimen>
<dimen name="round_circle_height">6dp</dimen>
<dimen name="round_circle_width">6dp</dimen>
<dimen name="total_score_right_margin">26dp</dimen>
<dimen name="total_score_left_margin">5dp</dimen>
<dimen name="score_text_size">12sp</dimen>
<dimen name="trivia_logo_height">25dp</dimen>
<dimen name="trivia_logo_width">84dp</dimen>
<dimen name="trivia_logo_margin_left">8dp</dimen>
<dimen name="question_margin_left">26dp</dimen>
<dimen name="question_margin_right">26dp</dimen>
<dimen name="question_top_margin">15dp</dimen>
<dimen name="question_margin_bottom">20dp</dimen>
<dimen name="question_text_size">12sp</dimen>
<dimen name="fun_fact_margin_bottom">100dp</dimen>
<dimen name="fun_fact_text_size">12dp</dimen>
<dimen name="answer_row_height">25dp</dimen>
</resources>
If I create a values-hdpi folder with this file
dimens.xml
30.00dp
10.50dp
10.50dp
18.00dp
27.00dp
18.00dp
30.00dp
27.00dp
90.00dp
18.00dp
30.00dp
30.00dp
42.00dp
9.00dp
9.00dp
9.00dp
39.00dp
7.50dp
18.00dp
37.50dp
126.00dp
8dp
39.00dp
39.00dp
22.50dp
30.00dp
18.00dp
150.00dp
18.00dp
37.50dp
everything will work fine
The values-es and values-fr are just folders containing strings.xml NO dimens in there. I reference all throughout my layout xml files with #dimen/answer_row_height for example.
As I stated before it works perfectly if I drop in the values-hdpi with a scaled dimens.xml file in it, but if I remove it Android does not scale it. Has anyone hit this before or know what i'm screwing up?
Values will not be automatically scaled, only drawables will be.
It's up to you to define all the alternative resources (values included) that your app will need, the framework cannot and will not make those decisions for you.
According to the documentation Android OS will assume your dimens.xml
is created for mdpi and scale accordingly for hdpi, xhdpi, etc...
That is incorrect. Whatever you put in dimens.xml is going to be used as is, if the dimensions are in pixels (px). You'll need to put them in density-independent-pixels (dp) to make them scale. dimens.xml should not be based on resolution but on screen size. You might have a dimens.xml in values and in values-large, specifying different spacing, or even different font-sizes for larger screens.
You should not have a dimens.xml in values and values-hdpi, because the dp unit already takes care of density-scaling.
Based on the comments you left in various places, it appears that you are not accessing the dimensions resources correctly. You should be using something like:
getResources().getDimensionPixelSize( R.dimen. round_circle_height );
if retrieving values from code, or
#dimen/round_circle_height
if referencing from xml.