Different values folders in android

2018-12-31 11:57发布

I am creating different values folders in my app (values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-nodpi, values-w360dp-mdpi). But some devices that belong same category. But having different screen sizes. But I see give font size according to device densities in this the answer provided by @PankajSharma suggest to create folders like-

res/values/dimens.xml    
res/values-small/dimens.xml    
res/values-normal/dimens.xml    
res/values-xlarge/dimens.xml

I want to know what is the difference b/w my way and the other way? I think the answer provided by @PankajSharma is easy. I also want to know which way is better?

3条回答
有味是清欢
2楼-- · 2018-12-31 12:31

The approach you are using is a valid approach, but a little outdated. From HoneyComb, there is a new way to fix all of this. Your resources folder should now look like this:

enter image description here

Please refer to the link I have posted and familiarize yourself with Smallest Width concept.

Hope this helps :)

EDIT: Adding to this post, try to establish some kind of standardization in your dimens.xml, something like this:

enter image description here

Doing this makes it easier to maintain code, plus it reduces the number of dimen folders. Normally rather than having values-hdpi, values-xhdpi, etc. files like values-sw480dp-xhdpi might have more values to adjust, but then again all of this is contextual.

查看更多
浪荡孟婆
3楼-- · 2018-12-31 12:31
<dimen name="activity_horizontal_margin">16dp</dimen>
<dimen name="activity_vertical_margin">16dp</dimen>

<!-- Various Text Sizes -->
<dimen name="text_size_extra_small">10sp</dimen>
<dimen name="text_size_small">12sp</dimen>
<dimen name="text_size_medium">14sp</dimen>
<dimen name="text_size_normal">16sp</dimen>
<dimen name="text_size_large">18sp</dimen>
<dimen name="text_size_extra_large">20sp</dimen>
<dimen name="text_size_super_large">50sp</dimen>
<dimen name="text_size_super_extra_large">70sp</dimen>

<!-- Various Paddings -->
<dimen name="padding_very_short">2dp</dimen>
<dimen name="padding_short">5dp</dimen>
<dimen name="padding_medium">7dp</dimen>
<dimen name="padding_normal">10dp</dimen>
<dimen name="padding_long">35dp</dimen>
<dimen name="padding_long_gamename">55dp</dimen>
<dimen name="padding_extra_long">15dp</dimen>

<!-- Various Margins -->
<dimen name="margin_very_short">5dp</dimen>
<dimen name="margin_med_short">5dp</dimen>
<dimen name="margin_short">10dp</dimen>
<dimen name="margin_meium">15dp</dimen>
<dimen name="margin_short_player_review">10dp</dimen>
<dimen name="margin_meium_player_review">15dp</dimen>
<dimen name="margin_normal">20dp</dimen>
<dimen name="margin_long">25dp</dimen>
<dimen name="margin_vshape">25dp</dimen>

<!-- Various Width -->
<dimen name="width_extra_min">120dp</dimen>
<dimen name="width_profile_messages_images">70dp</dimen>
<dimen name="width_half">240dp</dimen>
<dimen name="width_normal">300dp</dimen>
<dimen name="width_extra_large">360dp</dimen>
<dimen name="width_popup_window">180dp</dimen>


<!-- Various Height -->
<dimen name="height_very_short_shadow">1dp</dimen>
<dimen name="height_short">40dp</dimen>
<dimen name="width_ListHalf">260dp</dimen>

查看更多
何处买醉
4楼-- · 2018-12-31 12:32

Create a Single layout for default screens 4.7 inch (hdpi) in layout folder and dimensions in values folder. This is your Superset.

Now let say you want your layouts for 7inch devices. Create values-sw600dp folder for 7inch in Portrait orientation

Now lets say you want your layouts for 10 inch devices Create values-dw720dp folder

NOTE :- For landscape just add "-land" in front of folder names.

Now lets say you have new devices such as Xperia SP (4.7' and XHDPI) and Nexus 5(5" and XXHDPI).

For these, you can create values-xhdpi and values-xxhdpi folders and similary add -land for landscape orientation..

I hope you got the point of how to create folders..

Now your superset is defined in values folder. Most of the dimensions will be used from here only. Now run your app in other devices. Whatever mismatch is occuring just add that specific dimension in their respective values folder

To check from which folder your layouts, images are used, use my trick.

Create five same strings and put in it all the values folders like this :- Default Screen Screen 4.7 XHDPI Screen MDPI Screen

Create five drawable folders, most of them will be already there : - drawable-hdpi, drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, drawable-xxxhdpi Put the screenshots below in their respective folder under the same name

enter image description here enter image description here enter image description here enter image description here enter image description here

This is how my res folder looks like and i am supporting all the devices from 4.7 screen and above :-

enter image description here

查看更多
登录 后发表回答