下面列出了怎么用androidx.annotation.DimenRes的API类实例代码及写法,或者点击链接到github查看源代码。
@DimenRes
public static int getDetailSizeResId() {
switch (getDetailSize()) {
default:
case 0:
return R.dimen.gallery_list_column_width_long;
case 1:
return R.dimen.gallery_list_column_width_short;
}
}
@DimenRes
public static int getThumbSizeResId() {
switch (getThumbSize()) {
case 0:
return R.dimen.gallery_grid_column_width_large;
default:
case 1:
return R.dimen.gallery_grid_column_width_middle;
case 2:
return R.dimen.gallery_grid_column_width_small;
}
}
/**
* 获取 Dimension
* @param id resource identifier
* @return Dimension
*/
public static float getDimension(@DimenRes final int id) {
try {
return DevUtils.getContext().getResources().getDimension(id);
} catch (Exception e) {
LogPrintUtils.eTag(TAG, e, "getDimension");
}
return 0f;
}
public int resolveDimenSizeRes(@DimenRes int resId) {
if (resId != 0) {
Integer cached = mResourceCache.get(resId);
if (cached != null) {
return cached;
}
int result = mResources.getDimensionPixelSize(resId);
mResourceCache.put(resId, result);
return result;
}
return 0;
}
public int resolveDimenOffsetRes(@DimenRes int resId) {
if (resId != 0) {
Integer cached = mResourceCache.get(resId);
if (cached != null) {
return cached;
}
int result = mResources.getDimensionPixelOffset(resId);
mResourceCache.put(resId, result);
return result;
}
return 0;
}
public float resolveFloatRes(@DimenRes int resId) {
if (resId != 0) {
Float cached = mResourceCache.get(resId);
if (cached != null) {
return cached;
}
float result = mResources.getDimension(resId);
mResourceCache.put(resId, result);
return result;
}
return 0;
}
public int resolveDimenSizeAttr(@AttrRes int attrResId, @DimenRes int defResId) {
TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId});
try {
return a.getDimensionPixelSize(0, resolveDimenSizeRes(defResId));
} finally {
a.recycle();
}
}
public float resolveFloatAttr(@AttrRes int attrResId, @DimenRes int defResId) {
TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId});
try {
return a.getDimension(0, resolveFloatRes(defResId));
} finally {
a.recycle();
}
}
/**
* Set {@code start}, {@code top}, {@code end} and {@code bottom} padding for zooming and scrolling area using dimension.
*
* @return This Builder object to allow for chaining of calls to set methods
*/
public Builder setContainerPadding(Context context,
@DimenRes int start, @DimenRes int top,
@DimenRes int end, @DimenRes int bottom) {
setContainerPaddingPx(
Math.round(context.getResources().getDimension(start)),
Math.round(context.getResources().getDimension(top)),
Math.round(context.getResources().getDimension(end)),
Math.round(context.getResources().getDimension(bottom))
);
return this;
}
private int readDimen(@DimenRes int dimenId) {
return context.getResources().getDimensionPixelOffset(dimenId);
}
private int readDimen(@NonNull Context context, @DimenRes int dimenId) {
return context.getResources().getDimensionPixelOffset(dimenId);
}
public static float getFloat(@NonNull Context context, @DimenRes int resId) {
TypedValue value = new TypedValue();
context.getResources().getValue(resId, value, true);
return value.getFloat();
}
private int readDimen(@DimenRes int dimenRes) {
return getResources().getDimensionPixelSize(dimenRes);
}
private int getDimen(@DimenRes int dimenId) {
return getContext().getResources().getDimensionPixelSize(dimenId);
}
public TimelineItemDecorator(@NonNull Context context, @DimenRes int dimenRes) {
pixelOffset = context.getResources().getDimensionPixelOffset(dimenRes);
}
public static float getDimen(@DimenRes int dimen) {
return getResouces().getDimension(dimen);
}
public T sizeResId(@DimenRes int sizeId) {
return size(mResources.getDimensionPixelSize(sizeId));
}
public T spaceResId(@DimenRes int spaceId) {
return space(mResources.getDimensionPixelSize(spaceId));
}
public Builder marginResId(@DimenRes int topMarginId, @DimenRes int bottomMarginId) {
return margin(mResources.getDimensionPixelSize(topMarginId),
mResources.getDimensionPixelSize(bottomMarginId));
}
public Builder marginResId(@DimenRes int verticalMarginId) {
return marginResId(verticalMarginId, verticalMarginId);
}
public Builder marginResId(@DimenRes int leftMarginId, @DimenRes int rightMarginId) {
return margin(mResources.getDimensionPixelSize(leftMarginId),
mResources.getDimensionPixelSize(rightMarginId));
}
public T sizeResId(@DimenRes int sizeId) {
return size(mResources.getDimensionPixelSize(sizeId));
}
public T spaceResId(@DimenRes int spaceId) {
return space(mResources.getDimensionPixelSize(spaceId));
}
public Builder marginResId(@DimenRes int topMarginId, @DimenRes int bottomMarginId) {
return margin(mResources.getDimensionPixelSize(topMarginId),
mResources.getDimensionPixelSize(bottomMarginId));
}
public Builder marginResId(@DimenRes int verticalMarginId) {
return marginResId(verticalMarginId, verticalMarginId);
}
public int getDimensionPixelSize(@DimenRes int dimen) {
return getResources().getDimensionPixelSize(dimen);
}
public Builder marginResId(@DimenRes int horizontalMarginId) {
return marginResId(horizontalMarginId, horizontalMarginId);
}
StaggeredGridLayoutManagerItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) {
this(context.getResources().getDimensionPixelSize(itemOffsetId));
}
public Builder withDensity(@DimenRes int density) {
this.density = density;
return this;
}
public ItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) {
this(context.getResources().getDimensionPixelSize(itemOffsetId));
}