我已经在Google上搜索了如何在不同屏幕尺寸下设置textview尺寸很长时间了,但我仍然没有得到解决方案。
我已经尝试将其设置为“dp”或“sp”,但在不同的屏幕尺寸下尺寸仍然不同。
我也尝试使用下面的代码来更改大小,但结果仍然错误。
final float scale = getResources().getDisplayMetrics().density;
textview = (int) (mysize * scale + 0.5f);
我可以使用其他方法来确保任何屏幕尺寸下的比例都是正确的吗?
谢谢。
最佳答案
我已经尝试将其设置为'dp'或'sp'。您必须使用 sp
。
您可以使用此逻辑。
DisplayMetrics: A structure describing general information about a display, such as its size, density, and font scaling.
DisplayMetrics metrics = getResources().getDisplayMetrics();
int DeviceTotalWidth = metrics.widthPixels;
int DeviceTotalHeight = metrics.heightPixels;
TextViewObj.setTextSize(DeviceTotalWidth/8); // As per your Requirement
关于Android TextView在不同屏幕尺寸下的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34781516/