android - Android 中的大小单位是如何应用的?

标签 android android-studio xamarin view units-of-measurement

在axml文件中添加 View 时,可以简单地指定 View 属性的大小和单位,例如:

<TextView
    android:TextSize = "10sp"
    android:layout_marginTop = "10dp" />

但是当以编程方式应用尺寸时,尺寸 sp 应用的单位是什么? DP?像素?

TextView tv = new TextView();
tv.TextSize = 10;

另外,如何转换单位?

最佳答案

spTextView.TextSize 的默认值:

Set the default text size to the given value, interpreted as "scaled pixel" units. This size is adjusted based on the current density and user font size preference.`

如果您需要不同的单位类型 (ComplexUnitType),请使用 SetTextSize 方法:

textview.SetTextSize(ComplexUnitType.Px, 20);

关于android - Android 中的大小单位是如何应用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54638131/

相关文章:

java - Android 架构的第一步 - 请帮我避免一个大错误

android - 模拟器在运行Helloworld程序时停在开机界面

java - 无法将 android.support.v4.view.MenuItemCompat 转换到 android.widget.ShareActionProvider

c# - 将 Xamarin.forms 应用程序上的目标框架从 Android 8.1 更改为 Android 9(对于 Xamarin.Essentials)

android - 特定 Android 版本的值文件夹

android - 始终显示一个按钮

android - RecyclerView 项目装饰的负边距

Android 平板电脑在连接到 Mac 时卡住 - OS X

带有可以滚动到屏幕外的非粘性标题行的 Android ListView

android - 错误 : Cannot get property 'compileSdkVersion' on extra properties extension as it does not exist