Android使用错误的布局? [英] Android using wrong layout?

查看:86
本文介绍了Android使用错误的布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为不同的电话创建不同的布局.

I need to create diffrent layouts for diffrent phones.

我检查了3部手机和屏幕尺寸:

I chekced 3 phones and screen sizes:

SONY XPERIA Z:
08-30 09:04:05.258 1008-1008/pl.graphicbox.polamp I/LAYOUT: widthPixels  = 1080
08-30 09:04:05.258 1008-1008/pl.graphicbox.polamp I/LAYOUT: heightPixels = 1776
08-30 09:04:05.258 1008-1008/pl.graphicbox.polamp I/LAYOUT: densityDpi   = 480
08-30 09:04:05.258 1008-1008/pl.graphicbox.polamp I/LAYOUT: xdpi         = 442.451
08-30 09:04:05.258 1008-1008/pl.graphicbox.polamp I/LAYOUT: ydpi         = 443.345

Samsung s3:
08-30 09:05:00.179 21820-21820/pl.graphicbox.polamp I/LAYOUT: widthPixels  = 480
08-30 09:05:00.179 21820-21820/pl.graphicbox.polamp I/LAYOUT: heightPixels = 800
08-30 09:05:00.179 21820-21820/pl.graphicbox.polamp I/LAYOUT: densityDpi   = 240
08-30 09:05:00.179 21820-21820/pl.graphicbox.polamp I/LAYOUT: xdpi         = 234.0
08-30 09:05:00.179 21820-21820/pl.graphicbox.polamp I/LAYOUT: ydpi         = 236.0

Sony xperia M
08-30 09:08:25.964 5391-5391/pl.graphicbox.polamp I/LAYOUT: widthPixels  = 720
08-30 09:08:25.964 5391-5391/pl.graphicbox.polamp I/LAYOUT: heightPixels = 1184
08-30 09:08:25.964 5391-5391/pl.graphicbox.polamp I/LAYOUT: densityDpi   = 320
08-30 09:08:25.964 5391-5391/pl.graphicbox.polamp I/LAYOUT: xdpi         = 345.056
08-30 09:08:25.964 5391-5391/pl.graphicbox.polamp I/LAYOUT: ydpi         = 342.231

我创建了3种布局:

layout-sw200dp
layout-sw300dp
layout-sw400dp

但所有电话都使用相同的布局layout-sw300dp.

but all phones using the same layout layout-sw300dp.

有人可以向我解释我做错了什么以及如何解决此问题. 谢谢.

推荐答案

看起来所有电话的宽度都在300到400 dp之间,使用sw300dp时是正确的. 要检查它,请将dpWidth添加到日志中:

looks like all phones have a width between 300 and 400 dp, and it is correct, when they use sw300dp. To check it, add the dpWidth to the log:

Display display = getWindowManager().getDefaultDisplay();
DisplayMetrics outMetrics = new DisplayMetrics ();
display.getMetrics(outMetrics);

float density  = getResources().getDisplayMetrics().density;
float dpWidth  = outMetrics.widthPixels / density;

这篇关于Android使用错误的布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆