简体   繁体   English

如何为Galaxy S4和Nexus 4创建不同的布局

[英]How to create different layout for Galaxy S4 and Nexus 4

I am using "layout-sw360dp" for both Galaxy S4 and Nexus 4 devices but in my screen displaying some space on Galaxy S4. 我在Galaxy S4和Nexus 4设备上都使用“ layout-sw360dp”,但是在屏幕上显示的是Galaxy S4上的一些空间。 so can i make different layout for both Galaxy S4 and Nexus 4. if it is possible then please give me the solution. 因此,我可以为Galaxy S4和Nexus 4设置不同的布局吗?如果可以的话,请给我解决方案。

For Galaxy s4 use layout-xxhdpi 对于Galaxy s4,请使用layout-xxhdpi

For Nexus 4 use layout-xhdpi 对于Nexus 4,请使用layout-xhdpi

Galaxy S4 -- 1080 x 1920 pixels -- 5.0" -- 441 ppi -- xxhdpi
Nexus 4   -- 1280 x  768 pixels -- 4.7" -- 320 ppi -- xhdpi

You have to make different images to fit to the resolution of these devices 您必须制作不同的图像以适合这些设备的分辨率

As per other answers one device is 640 x 360 dp and the other 640 x 384 dp . 根据其他答案,一台设备为640 x 360 dp ,另一台为640 x 384 dp

You don't want to make a different layout for them, because you will sooner or later see a device 640 x 372 dp or 640 x 388 dp . 不想为它们设置不同的布局,因为您迟早会看到640 x 372 dp640 x 388 dp

Instead make your layout elastic and don't hardcode pixels (density independent pixels can also be badly hardcoded). 而是使布局具有弹性,并且不要对像素进行硬编码(与密度无关的像素也可能会被硬编码)。

ok here goes... for reference 好的这里去...供参考

  1. this is older layout folder naming conventions but you get the point. 这是较早的布局文件夹命名约定,但您明白了。

  2. You must convert everything to mdpi to go into the following buckets. 您必须将所有内容都转换为mdpi才能进入以下存储桶。

  3. buckets for layouts are : xlarge 960 x720 min large 640 x480 min normal 470 x 320 min small 426x 320 min 布局的存储桶为:x大960 x720分钟大640 x480分钟普通470 x 320分钟小426x 320分钟

  4. scaling ratio 3:4:6:8:12 this means that you must multiple ldpi * 3/4 to go from ldpi to mdpi and you must multiple mdpi * 4/6 to go from mdpi to hdpi and you must multiple hdpi * 6/8 to go from hdpi to xhdpi and you must multiple xhdpi * 8/12 to go from xhdpi to xxhdpi 缩放比例3:4:6:8:12这意味着您必须将多个ldpi * 3/4从ldpi转换为mdpi,并且必须将多个mdpi * 4/6从mdpi转换为hdpi,并且必须将多个hdpi * 6 / 8才能从hdpi转换为xhdpi,并且必须多个xhdpi * 8/12才能从xhdpi转换为xxhdpi

so to answer the question.... 所以回答这个问题。

s4 is xxhdpi which means the scaling ratio is 4/12 or 1/3. s4为xxhdpi,这表示缩放比例为4/12或1/3。 This means that you have to convert from xxhdpi to mdpi to place in a layout folder properly. 这意味着您必须从xxhdpi转换为mdpi才能正确放置在布局文件夹中。
so 1080 * 1/3 = 360 and 1920 * 1/3 = 640 so this would place it in a normal layout folder 因此1080 * 1/3 = 360和1920 * 1/3 = 640,因此可以将其放置在常规布局文件夹中

nexus 4 is xhdpi which means the scaling ratio is 4/8 or 1/2. 连结4为xhdpi,表示缩放比例为4/8或1/2。 4 This means that you have to convert from xhdpi to mdpi to place in a layout folder properly. 4这意味着您必须从xhdpi转换为mdpi才能正确放置在布局文件夹中。 so 1280 * 1/2 = 640 and 768 * 1/2 = 384 so this would place it in a normal layout folder as well. 因此1280 * 1/2 = 640和768 * 1/2 = 384,因此也可以将其放置在常规布局文件夹中。

ok, so this doesn't quite cut it because they are different resolutions. 好的,因为它们是不同的分辨率,所以并不能完全消除它。 we can make up folders with the new naming conventions. 我们可以使用新的命名约定来构成文件夹。 for example the smallest width for the s4 is 360 while the smallest width for the nexus 4 is 384. so folders could be sw360dp and sw384dp. 例如,s4的最小宽度为360,而nexus 4的最小宽度为384。因此文件夹可以是sw360dp和sw384dp。
you could also name the folder layout-xxhdpi which would catch the s4 but not the nexus 4 您也可以将文件夹layout-xxhdpi命名为可以捕获s4而不是nexus 4的文件夹

be aware: Just to throw another one out there what if you had an s3 as well. 请注意:如果您也有s3,只好丢掉另一个。 that would go in the sw360dp folder as well. 也会放在sw360dp文件夹中。 so I guess you would have to differ between them as well. 所以我想您也将不得不区别对待。 if you used layout-xxhdpi above then you could use sw360dp here and sw384dp above as well. 如果您在上方使用layout-xxhdpi,则可以在此处使用sw360dp,也可以在上方使用sw384dp。 cover them all. 掩盖所有。 thanks 谢谢

Both these phones have different screen size and resolution , 这两款手机的屏幕尺寸和分辨率不同
that leads to different density as well . 导致不同的密度。

As per my knowledge - 据我所知-

Galaxy s4 has 1080 x 1920 pixels, 5.0 inches (~441 ppi pixel density). Galaxy s4具有1080 x 1920像素,5.0英寸(〜441 ppi像素密度)。

And

Nexus 4 has 1280 x 768 pixels, 4.7 inches (320 ppi ). Nexus 4具有1280 x 768像素,4.7英寸(320 ppi)。

You will have to design the layouts (and images as well ) according to the phones specifications. 您将必须根据电话规格设计布局(以及图像)。

for nexus 4 use below layout. 对于nexus 4,请使用以下布局。

layout-sw360dp 布局-sw360dp

both galaxy s3 and nexus 4 have same layouts. 银河s3和连结4的布局相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM