当前位置: 首页>>代码示例>>Java>>正文


Java Dimension.DP属性代码示例

本文整理汇总了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));
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:5,代码来源:MetricsHelperTest.java

示例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);
}
 
开发者ID:customerly,项目名称:Customerly-Android-SDK,代码行数:7,代码来源:IU_Utils.java

示例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;
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:14,代码来源:MetricsHelper.java

示例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;
}
 
开发者ID:material-components,项目名称:material-components-android,代码行数:12,代码来源:TabLayout.java

示例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));
}
 
开发者ID:neworld,项目名称:spanner,代码行数:6,代码来源:Spans.java

示例6: testDpToPxInt

@Test
public void testDpToPxInt() {
  @Dimension(unit = Dimension.DP) int dp = 3;
  Assert.assertEquals(7, MetricsHelper.dpToPxInt(resources, dp));
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:5,代码来源:MetricsHelperTest.java

示例7: dpToPx

@Dimension(unit = Dimension.PX)
int dpToPx(@Dimension(unit = Dimension.DP) int dps) {
  return Math.round(getResources().getDisplayMetrics().density * dps);
}
 
开发者ID:material-components,项目名称:material-components-android,代码行数:4,代码来源:TabLayout.java

示例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;
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:11,代码来源:MetricsHelper.java

示例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);
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:11,代码来源:MetricsHelper.java

示例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;
}
 
开发者ID:xmartlabs,项目名称:bigbang,代码行数:11,代码来源:MetricsHelper.java


注:本文中的android.support.annotation.Dimension.DP属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。