简体   繁体   English

Android:在某些设备上裁剪文字

[英]Android: text cropped in some devices

In my android app, there is a certain layout with a fixed height. 在我的android应用中,有一个固定高度的布局。 In this layout, there are some TextView s arranged vertically. 在这种布局中,有一些TextView垂直排列。 I have set the font size of text fields to be somewhat larger (18sp). 我已将文本字段的字体大小设置为更大(18sp)。

In almost all the devices I checked, The text fits inside the fixed sized layout. 在我检查过的几乎所有设备中,文本都适合固定大小的布局。 But in few devices, The bottom TextView gets cropped out of the layout. 但是在少数设备中,底部的TextView会从布局中裁剪出来。

If the proportion between text unit size (sp) and the layout unit height (dp) is the same in all devices, I wouldn't expect this to happen. 如果在所有设备中文本单位大小(sp)和布局单位高度(dp)之间的比例相同,则我不希望这种情况发生。

So, is this due to something wrong with the devices? 那么,这是由于设备出现问题吗? Is there any way I can fix this? 有什么办法可以解决这个问题?

Screen density is different than screen dimensions. 屏幕密度与屏幕尺寸不同。 dp normalizes densities across devices, but they can still have varying screen heights and widths. dp标准化了设备上的密度,但是它们仍然可以具有变化的屏幕高度和宽度。 The obvious example is tablet vs phones, tablets have the same screen densities as phones but much larger screen dimensions. 平板电脑与手机的对比就是一个明显的例子,平板电脑的屏幕密度与手机相同,但屏幕尺寸却大得多。 Just like that, some phones have smaller screens than others, so you need to take that into account when using fixed height layouts. 就像这样,某些手机的屏幕要比其他手机小,因此在使用固定高度的布局时需要考虑到这一点。

To get around this problem, you can take advantage of the width and smallest-width resource buckets and provide different layouts for smaller devices. 要解决此问题,您可以利用widthsmallest-width资源桶,并为较小的设备提供不同的布局。

As it seems, the proportion between a unit sp and a unit dp depends on the font size setting (Settings->Display->Font size). 看起来,单位sp和单位dp之间的比例取决于字体大小设置(设置->显示->字体大小)。

I could recreate the issue on other devices when I set the font size to be Huge . 当我将字体大小设置为Huge时,可以在其他设备上重新创建该问题。

So, it is not a good idea to set fixed sizes to layouts containing text. 因此,将固定大小设置为包含文本的布局不是一个好主意。

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

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