测量单位 px、dip、dp 和 sp 的区别是什么?
当前回答
SDP - 一个可扩展的尺寸单位 - 基本上它不是一个单位,而是不同屏幕大小的尺寸资源。
在 Intuit 中尝试 sdp 图书馆. 解决单位问题非常方便,您可以快速支持多个屏幕。
使用
android:paddingBottom="@dimen/_15sdp" for positive and android:layout_marginTop="@dimen/_minus10sdp" for negative sdp sdp
它在每个尺寸的值-sw<N>dp 文件夹(sw = 最小Width)中具有相当值。
注意
在大多数情况下,你仍然需要为平板电脑设计不同的布局。
例子
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_minus10sdp"
android:paddingBottom="@dimen/_15sdp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="♡"
android:textColor="#ED6C27"
android:textSize="@dimen/_70sdp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="U"
android:textColor="@android:color/black"
android:textSize="@dimen/_70sdp" />
</LinearLayout>
你可以用db为文本大小,但我更喜欢ssp为文本大小。
更多详细信息请参阅图书馆 GitHub 页面。
其他回答
sp:尺寸独立像素
您应该使用它与文本,因为它是根据用户在其设备中使用的字体大小自动规模。
px:像素或图像元素是屏幕上的单点
我只会使用DP。
有很多关于使用“sp”字体尺寸的谈话,虽然我欣赏这一点,我不认为这是从设计观点做正确的事情,你可以结束打破你的设计,如果用户有一些有趣的字体尺寸的选择,用户将最终责怪应用程序,而不是自己的生活选择。
此外,如果你在160dpi平板电脑上使用 sp-font 应用程序,你会发现一切都在扩展......但你的字体,这在比较中会看起来很小。
虽然“sp”字体的想法有一个好心,但这是一个糟糕的想法。
计算像素密度
密度独立性
屏幕像素密度和分辨率取决于平台,设备独立的像素和可扩展的像素是提供一个灵活的方式,以适应整个平台的设计。
计算像素密度 匹配英寸的像素数量被称为像素密度. 高密度屏幕每英寸比低密度的像素多。
密度独立的像素,写作为dp(发音为“dips”),是灵活的单位,规模在任何屏幕上均匀的尺寸。
低密度屏幕显示与密度独立高密度屏幕显示与密度独立
SDP - 一个可扩展的尺寸单位 - 基本上它不是一个单位,而是不同屏幕大小的尺寸资源。
在 Intuit 中尝试 sdp 图书馆. 解决单位问题非常方便,您可以快速支持多个屏幕。
使用
android:paddingBottom="@dimen/_15sdp" for positive and android:layout_marginTop="@dimen/_minus10sdp" for negative sdp sdp
它在每个尺寸的值-sw<N>dp 文件夹(sw = 最小Width)中具有相当值。
注意
在大多数情况下,你仍然需要为平板电脑设计不同的布局。
例子
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_minus10sdp"
android:paddingBottom="@dimen/_15sdp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="♡"
android:textColor="#ED6C27"
android:textSize="@dimen/_70sdp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:text="U"
android:textColor="@android:color/black"
android:textSize="@dimen/_70sdp" />
</LinearLayout>
你可以用db为文本大小,但我更喜欢ssp为文本大小。
更多详细信息请参阅图书馆 GitHub 页面。
像素(px) - 相应于屏幕上的实际像素,如果您想要提供的绝对像素的宽度或高度。
总是使用 dp 和 sp 只. sp 用于字体大小和 dp 用于其他任何东西. 它将使 Android 设备与不同的密度兼容的 UI. 您可以从 https://www.google.com/design/spec/layout/units-measurements.html#units-measurements-density-independent-pixels-dp- 了解更多关于 pixel 和 dp 的信息。
来源 URL:- http://www.androidtutorialshub.com/what-is-the-difference-between-px-dp-dip-sp-on-android/
推荐文章
- Openssl不被视为内部或外部命令
- 无法执行dex:在Eclipse中超过GC开销限制
- 如何以编程方式将视图添加到视图
- 单击url会打开默认浏览器
- 使用Retrofit刷新OAuth令牌,而不修改所有调用
- 多个dex文件定义了landoid /support/v4/accessibilityservice/AccessibilityServiceInfoCompat
- 如何获得动作栏的高度?
- 从活动外部调用startActivity() ?
- createScaledBitmap的过滤器参数做什么?
- 为什么我在使用adb时访问数据文件夹被拒绝?
- 如何确定Android设备的GPS是否已启用
- 没有找到与给定名称匹配的资源:attr 'android:keyboardNavigationCluster'。更新到支持库26.0.0时
- 禁用在android中打开导航抽屉的滑动手势
- Android:允许平板电脑竖屏和横屏,但强制手机竖屏?
- 如何使布局与视图填充剩余的空间?