本文整理汇总了Java中android.support.annotation.Dimension.PX属性的典型用法代码示例。如果您正苦于以下问题:Java Dimension.PX属性的具体用法?Java Dimension.PX怎么用?Java Dimension.PX使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.annotation.Dimension
的用法示例。
在下文中一共展示了Dimension.PX属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sizePX
/**
* @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int)
*/
public static Span sizePX(@Dimension(unit = Dimension.PX) final int px) {
return new Span(new AbsoluteSizeSpanBuilder(px, false));
}
示例2: testPxToDp
@Test
public void testPxToDp() {
@Dimension(unit = Dimension.PX) float px = 3.5f;
Assert.assertEquals(1.4f, MetricsHelper.pxToDp(resources, px));
}
示例3: dpToPx
@Dimension(unit = Dimension.PX)
int dpToPx(@Dimension(unit = Dimension.DP) int dps) {
return Math.round(getResources().getDisplayMetrics().density * dps);
}
示例4: dpToPx
/**
* Converts the {@code dp} value to pixels dimension.
*
* @param resources to obtain the density value
* @param dp the value in dp dimension
* @return the converted {@code dp} value to pixels
*/
@Dimension(unit = Dimension.PX)
public static float dpToPx(@NonNull Resources resources, @Dimension(unit = Dimension.DP) float dp) {
return dp * resources.getDisplayMetrics().density;
}
示例5: spToPx
/**
* Converts the {@code sp} value to pixels dimension.
*
* @param resources to obtain the density value
* @param sp the value in sp dimension
* @return the converted {@code sp} value to pixels
*/
@Dimension(unit = Dimension.PX)
public static float spToPx(@NonNull Resources resources, @Dimension(unit = Dimension.SP) float sp) {
return sp * resources.getDisplayMetrics().scaledDensity;
}
示例6: dpToPxInt
/**
* Converts the {@code dp} value to pixels dimension.
*
* @param resources to obtain the density value
* @param dp the value in dp dimension
* @return the converted {@code dp} value to integer pixels
*/
@Dimension(unit = Dimension.PX)
public static int dpToPxInt(@NonNull Resources resources, @Dimension(unit = Dimension.DP) float dp) {
return (int) dpToPx(resources, dp);
}
示例7: dimResToPxInt
/**
* Converts the given {@code dimenId} resource to pixels.
*
* @param resources to obtain the density value
* @param dimenId the resource to convert
* @return the converted {@code dimenId} resource value to integer pixels
*/
@Dimension(unit = Dimension.PX)
public static int dimResToPxInt(@NonNull Resources resources, @DimenRes int dimenId) {
return (int) resources.getDimension(dimenId);
}
示例8: pxToDp
/**
* Converts the {@code px} value to dp.
*
* @param resources to obtain the density value
* @param px the value in pixels to convert to dp
* @return the converted {@code px} value to dp
*/
@Dimension(unit = Dimension.DP)
public static float pxToDp(@NonNull Resources resources, @Dimension(unit = Dimension.PX) float px) {
return px / resources.getDisplayMetrics().density;
}