简体   繁体   English

Android不同屏幕的相对布局

[英]Android relative layout with different screens

and thanks in advance. 并预先感谢。 I am currently developing a game based on words, and for that purpose I have designed a custom keyboard as a relative layout. 我目前正在开发基于文字的游戏,为此,我设计了一个自定义键盘作为相对布局。

At the moment, I am designing different resources for different screen sizes. 目前,我正在为不同的屏幕尺寸设计不同的资源。 So I have made different size resources for hdpi, mdpi and ldpi. 因此,我为hdpi,mdpi和ldpi设置了不同的大小资源。 The keyboard works excellent for hdpi screens, but it is displayed incorrectly for mdpi and ldpi screens(more so for ldpi screens). 键盘在hdpi屏幕上表现出色,但在mdpi和ldpi屏幕上显示不正确(对于ldpi屏幕更是如此)。 Here are the images which best describe this problem: 以下是最能描述此问题的图像:

hdpi screen:(240 dpi, 480x800) hdpi屏幕:(240 dpi,480x800)

http://pokit.org/get/?63036a53e89f5ea526a115177fc404e8.jpg http://pokit.org/get/?63036a53e89f5ea526a115177fc404e8.jpg

ldpi screen:(120 dpi, 240x320) ldpi屏幕:(120 dpi,240x320)

http://pokit.org/get/?612ec561ff10fdf49cf598d170a0e672.jpg http://pokit.org/get/?612ec561ff10fdf49cf598d170a0e672.jpg

As you can see, some of the images are larger and some are smaller even though they are all the same image(except for the "enter" key). 如您所见,即使它们都是相同的图像,某些图像还是较大的,有些较小(“ Enter”键除外)。 I cannot undestand why this happens. 我无法理解为什么会这样。

Here is the code of the keyboard(it is designed as a custom control). 这是键盘的代码(它被设计为自定义控件)。

http://pastebin.com/QJndxdex http://pastebin.com/QJndxdex

LDPI image is 20x29 px, hdpi image is 47x69. LDPI图片为20x29像素,hdpi图片为47x69。

EDIT: http://pastebin.com/a6dGdyay I am posting pastebin since the code is long. 编辑: http ://pastebin.com/a6dGdyay由于代码很长,我正在发布pastebin。 Apparently, the first 5 letters are englarged for some reason, all others are displayed correctly. 显然,前5个字母由于某种原因而被放大,所有其他字母均正确显示。

Change your textSize sp to 'dp' as this also considers density of each screen which causes layouts to change dimensions. 将您的textSize sp更改为“ dp”,因为这还会考虑每个屏幕的密度,这会导致布局更改尺寸。 SP is preferred way by Google but it usually kills the layout that when most of it is graphics and not text. SP是Google首选的方式,但通常会杀死大多数图形而不是文本的布局。

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

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