如何为android中的每个不同屏幕尺寸定义dimens

如何为android中的每个不同屏幕尺寸定义dimens

本文介绍了如何为android中的每个不同屏幕尺寸定义dimens.xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android 中支持不同的屏幕尺寸(密度)时,通常重点是为每个可能的屏幕创建不同的布局.即

  • ldpi
  • mdpi
  • hdpi
  • xhdpi
  • xxhdpi
  • xxxhdpi

我为xhdpi 屏幕设计了一个布局作为参考,并在dimens.xml 中定义了它的尺寸>.现在我想为所有可能的屏幕尺寸提供支持.我该怎么做?

据我所知,我可以使用

有关更多信息,您可以访问此处

android 中的不同值文件夹

http://android-developer.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html

编辑@humblerookie

您可以使用名为 Dimenify 的 Android Studio 插件自动生成维度基于自定义比例因子的其他像素桶的值.它仍处于测试阶段,请务必将您遇到的任何问题/建议通知开发者.

When supporting different screen sizes (densities) in Android often the focus is on creating different layouts for every possible screen. I.E.

  • ldpi
  • mdpi
  • hdpi
  • xhdpi
  • xxhdpi
  • xxxhdpi

I designed a layout for an xhdpi screen as a reference, and defined it's dimensions in dimens.xml. Now I want to give support it to every possible screen size. How can I do that?

As far as I know, I can use this tool to figure out the proper dimens.xml for other screen sizes and add it to my project. Is this the right way to do it in my situation?

Another question, do I only need to create dimens.xml for above screen dimensions? If yes then what is w820dp?

Thanks for your help. I need to support phones only (not tablets or other devices).

解决方案

You have to create Different values folder for different screens .Like

values-sw720dp          10.1" tablet 1280x800 mdpi

values-sw600dp          7.0"  tablet 1024x600 mdpi

values-sw480dp          5.4"  480x854 mdpi
values-sw480dp          5.1"  480x800 mdpi

values-xxhdpi           5.5"  1080x1920 xxhdpi
values-xxxhdpi           5.5" 1440x2560 xxxhdpi

values-xhdpi            4.7"   1280x720 xhdpi
values-xhdpi            4.65"  720x1280 xhdpi

values-hdpi             4.0" 480x800 hdpi
values-hdpi             3.7" 480x854 hdpi

values-mdpi             3.2" 320x480 mdpi

values-ldpi             3.4" 240x432 ldpi
values-ldpi             3.3" 240x400 ldpi
values-ldpi             2.7" 240x320 ldpi

For more information you may visit here

Edited By @humblerookie

You can make use of Android Studio plugin called Dimenify to auto generate dimension values for other pixel buckets based on custom scale factors. Its still in beta, be sure to notify any issues/suggestions you come across to the developer.

这篇关于如何为android中的每个不同屏幕尺寸定义dimens.xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:49