本文整理汇总了Java中android.support.annotation.Dimension.DP属性的典型用法代码示例。如果您正苦于以下问题:Java Dimension.DP属性的具体用法?Java Dimension.DP怎么用?Java Dimension.DP使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.annotation.Dimension
的用法示例。
在下文中一共展示了Dimension.DP属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDpToPx
@Test
public void testDpToPx() {
@Dimension(unit = Dimension.DP) int dp = 10;
Assert.assertEquals(25.0f, MetricsHelper.dpToPx(resources, dp));
}
示例2: px
@Contract(pure = true)
@Px static int px(@Dimension(unit = Dimension.DP) int dp) {
float dpi = Resources.getSystem().getDisplayMetrics().density;
dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi;
dpi = dpi == 0 ? 1f : dpi;
return (int) (dp * dpi);
}
示例3: getToolbarHeight
/**
* Retrieves the toolbar height of the current app theme.
*
* @param theme the device {@link Theme}
* @param actionBarSize the current {@link ActionBar} size
* @return the toolbar height of the current app theme
*/
@Dimension(unit = Dimension.DP)
public static int getToolbarHeight(@NonNull Theme theme, @AttrRes int actionBarSize) {
final TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {actionBarSize});
int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
styledAttributes.recycle();
return toolbarHeight;
}
示例4: getDefaultHeight
@Dimension(unit = Dimension.DP)
private int getDefaultHeight() {
boolean hasIconAndText = false;
for (int i = 0, count = tabs.size(); i < count; i++) {
Tab tab = tabs.get(i);
if (tab != null && tab.getIcon() != null && !TextUtils.isEmpty(tab.getText())) {
hasIconAndText = true;
break;
}
}
return (hasIconAndText && !inlineLabel) ? DEFAULT_HEIGHT_WITH_TEXT_ICON : DEFAULT_HEIGHT;
}
示例5: sizeDP
/**
* @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int, boolean)
*/
public static Span sizeDP(@Dimension(unit = Dimension.DP) final int dp) {
return new Span(new AbsoluteSizeSpanBuilder(dp, true));
}
示例6: testDpToPxInt
@Test
public void testDpToPxInt() {
@Dimension(unit = Dimension.DP) int dp = 3;
Assert.assertEquals(7, MetricsHelper.dpToPxInt(resources, dp));
}
示例7: dpToPx
@Dimension(unit = Dimension.PX)
int dpToPx(@Dimension(unit = Dimension.DP) int dps) {
return Math.round(getResources().getDisplayMetrics().density * dps);
}
示例8: 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;
}
示例9: 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);
}
示例10: 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;
}