本文整理匯總了Java中android.content.res.Resources.getDimension方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getDimension方法的具體用法?Java Resources.getDimension怎麽用?Java Resources.getDimension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getDimension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDefaultKeyboardHeight
import android.content.res.Resources; //導入方法依賴的package包/類
public static int getDefaultKeyboardHeight(final Resources res) {
final DisplayMetrics dm = res.getDisplayMetrics();
final String keyboardHeightInDp = getDeviceOverrideValue(
res, R.array.keyboard_heights, null /* defaultValue */);
final float keyboardHeight;
if (TextUtils.isEmpty(keyboardHeightInDp)) {
keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height);
} else {
keyboardHeight = Float.parseFloat(keyboardHeightInDp) * dm.density;
}
final float maxKeyboardHeight = res.getFraction(
R.fraction.config_max_keyboard_height, dm.heightPixels, dm.heightPixels);
float minKeyboardHeight = res.getFraction(
R.fraction.config_min_keyboard_height, dm.heightPixels, dm.heightPixels);
if (minKeyboardHeight < 0.0f) {
// Specified fraction was negative, so it should be calculated against display
// width.
minKeyboardHeight = -res.getFraction(
R.fraction.config_min_keyboard_height, dm.widthPixels, dm.widthPixels);
}
// Keyboard height will not exceed maxKeyboardHeight and will not be less than
// minKeyboardHeight.
return (int)Math.max(Math.min(keyboardHeight, maxKeyboardHeight), minKeyboardHeight);
}
示例2: onApplyWindowInsets
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void onApplyWindowInsets(WindowInsets insets) {
super.onApplyWindowInsets(insets);
// Load resources that have alternate values for round watches.
Resources resources = MyWatchFace.this.getResources();
boolean isRound = insets.isRound();
mXOffset = resources.getDimension(isRound
? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
float textSize = resources.getDimension(isRound
? R.dimen.digital_text_size_round : R.dimen.digital_text_size);
hourPaint.setTextSize(textSize);
minutePaint.setTextSize(textSize);
colonPaint.setTextSize(textSize);
highPaint.setTextSize(textSize);
lowPaint.setTextSize(textSize);
colonWidth = colonPaint.measureText(":");
}
示例3: getItemOffsets
import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
Resources r = context.getResources();
int horizontalPadding = (int) r.getDimension(R.dimen.category_preview__app_list__padding__horizontal);
int horizontalPaddingFirst = (int) r.getDimension(
R.dimen.category_preview__app_list__padding__horizontal__first);
boolean isLtr = ViewCompat.getLayoutDirection(parent) == ViewCompat.LAYOUT_DIRECTION_LTR;
int itemPosition = parent.getChildLayoutPosition(view);
boolean first = itemPosition == 0;
// Leave this "paddingEnd" local variable here for clarity when converting from
// left/right to start/end for RTL friendly layout.
// noinspection UnnecessaryLocalVariable
int paddingEnd = horizontalPadding;
int paddingStart = first ? horizontalPaddingFirst : horizontalPadding;
int paddingLeft = isLtr ? paddingStart : paddingEnd;
int paddingRight = isLtr ? paddingEnd : paddingStart;
outRect.set(paddingLeft, 0, paddingRight, 0);
}
示例4: measureInWindow
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Returns the coordinates of a view relative to the window (not just the RootView
* which is what measure will return)
*
* @param tag - the tag for the view
* @param outputBuffer - output buffer that contains [x,y,width,height] of the view in coordinates
* relative to the device window
*/
public void measureInWindow(int tag, int[] outputBuffer) {
UiThreadUtil.assertOnUiThread();
View v = mTagsToViews.get(tag);
if (v == null) {
throw new NoSuchNativeViewException("No native view for " + tag + " currently exists");
}
v.getLocationOnScreen(outputBuffer);
// We need to remove the status bar from the height. getLocationOnScreen will include the
// status bar.
Resources resources = v.getContext().getResources();
int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android");
if (statusBarId > 0) {
int height = (int) resources.getDimension(statusBarId);
outputBuffer[1] -= height;
}
// outputBuffer[0,1] already contain what we want
outputBuffer[2] = v.getWidth();
outputBuffer[3] = v.getHeight();
}
示例5: ControllerV16
import android.content.res.Resources; //導入方法依賴的package包/類
public ControllerV16(View header) {
Resources res = header.getContext().getResources();
mScrollToElevation = res.getDimension(R.dimen.all_apps_header_scroll_to_elevation);
mShadow = new View(header.getContext());
mShadow.setBackground(new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0x1E000000, 0x00000000}));
mShadow.setAlpha(0);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
res.getDimensionPixelSize(R.dimen.all_apps_header_shadow_height));
lp.topMargin = ((FrameLayout.LayoutParams) header.getLayoutParams()).height;
((ViewGroup) header.getParent()).addView(mShadow, lp);
}
示例6: setIsUsingBigIcon
import android.content.res.Resources; //導入方法依賴的package包/類
/**
* Adjusts styling to account for the big icon layout.
*/
public void setIsUsingBigIcon() {
LayoutParams lp = (LayoutParams) mIconView.getLayoutParams();
lp.width = mBigIconSize;
lp.height = mBigIconSize;
lp.endMargin = mBigIconMargin;
Resources res = getContext().getResources();
String typeface = res.getString(R.string.roboto_medium_typeface);
int textStyle = res.getInteger(R.integer.roboto_medium_textstyle);
float textSize = res.getDimension(R.dimen.infobar_big_icon_message_size);
mMessageTextView.setTypeface(Typeface.create(typeface, textStyle));
mMessageTextView.setMaxLines(1);
mMessageTextView.setEllipsize(TextUtils.TruncateAt.END);
mMessageTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
示例7: getHeaderFooterRowHeight
import android.content.res.Resources; //導入方法依賴的package包/類
public int getHeaderFooterRowHeight(int section, boolean isFooterRow) {
Resources res = mTableView.getResources();
// pull height, it will default on delegate to UNDEFINED if not
// overridden.
int rowHeight = ATableViewCell.LayoutParams.UNDEFINED;
if (isFooterRow) {
rowHeight = section < mFootersHeight.size() ? mFootersHeight.get(section) : 0;
} else {
rowHeight = section < mHeadersHeight.size() ? mHeadersHeight.get(section) : 0;
}
// if undefined, set a valid height depending on table style, otherwise
// use overridden value.
if (rowHeight == ATableViewCell.LayoutParams.UNDEFINED) {
if (mTableView.getStyle() == ATableViewStyle.Plain) {
rowHeight = (int) res
.getDimension(R.dimen.atv_plain_section_header_height);
} else {
rowHeight = ListView.LayoutParams.WRAP_CONTENT;
}
}
// convert row height value when an scalar was used.
if (rowHeight > -1) {
rowHeight = (int) Math.ceil(rowHeight
* res.getDisplayMetrics().density);
}
return rowHeight;
}
示例8: CirclePageIndicator
import android.content.res.Resources; //導入方法依賴的package包/類
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) return;
//Load defaults from resources
final Resources res = getResources();
final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
//Retrieve styles attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);
mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
mPaintPageFill.setStyle(Style.FILL);
mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
mPaintStroke.setStyle(Style.STROKE);
mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
mPaintFill.setStyle(Style.FILL);
mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
if (background != null) {
setBackgroundDrawable(background);
}
a.recycle();
final ViewConfiguration configuration = ViewConfiguration.get(context);
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
示例9: initializeWatchFaceElements
import android.content.res.Resources; //導入方法依賴的package包/類
private void initializeWatchFaceElements(Resources resources){
mBackgroundPaint = new Paint();
mBackgroundPaint.setColor(resources.getColor(R.color.background));
mTimeTextPaint = new Paint();
mTimeTextPaint.setColor(resources.getColor(R.color.digital_time));
mTimeTextPaint.setTypeface(NORMAL_TYPEFACE);
mTimeTextPaint.setAntiAlias(true);
mDateTextPaint = new Paint();
mDateTextPaint.setTextSize(resources.getDimension(R.dimen.digital_text_date_size));
mDateTextPaint.setColor(resources.getColor(R.color.digital_date));
mDateTextPaint.setTypeface(NORMAL_TYPEFACE);
mDateTextPaint.setAntiAlias(true);
mIconBitmappaint=new Paint();
mMaxTempTextPaint= new Paint();
mMaxTempTextPaint.setColor(resources.getColor(R.color.digital_maxT));
mMaxTempTextPaint.setTextSize(resources.getDimension(R.dimen.digital_text_MaxT_size));
mMaxTempTextPaint.setTypeface(NORMAL_TYPEFACE);
mMaxTempTextPaint.setAntiAlias(true);
mMinTempTextPaint= new Paint();
mMinTempTextPaint.setColor(resources.getColor(R.color.digital_minT));
mMinTempTextPaint.setTextSize(resources.getDimension(R.dimen.digital_text_MinT_size));
mMinTempTextPaint.setTypeface(NORMAL_TYPEFACE);
mMinTempTextPaint.setAntiAlias(true);
mYOffset = resources.getDimension(R.dimen.digital_y_offset);
mCalendar = Calendar.getInstance();
mDate = new Date();
}
示例10: CirclePageIndicator
import android.content.res.Resources; //導入方法依賴的package包/類
public CirclePageIndicator(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
if (isInEditMode()) return;
//Load defaults from resources
final Resources res = getResources();
final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
//Retrieve styles attributes
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);
mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
mPaintPageFill.setStyle(Style.FILL);
mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
mPaintStroke.setStyle(Style.STROKE);
mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
mPaintFill.setStyle(Style.FILL);
mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);
Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
if (background != null) {
setBackgroundDrawable(background);
}
a.recycle();
final ViewConfiguration configuration = ViewConfiguration.get(context);
mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}
示例11: loadDimens
import android.content.res.Resources; //導入方法依賴的package包/類
private void loadDimens() {
Resources res = getContext().getResources();
this.mSelfExpandVelocityPx = res.getDimension(R.dimen.self_expand_velocity);
this.mSelfCollapseVelocityPx = res.getDimension(R.dimen.self_collapse_velocity);
this.mFlingExpandMinVelocityPx = res.getDimension(R.dimen.fling_expand_min_velocity);
this.mFlingCollapseMinVelocityPx = res.getDimension(R.dimen.fling_collapse_min_velocity);
this.mFlingGestureMinDistPx = res.getDimension(R.dimen.fling_gesture_min_dist);
this.mCollapseMinDisplayFraction = res.getFraction(R.fraction.collapse_min_display_fraction, 1, 1);
this.mExpandMinDisplayFraction = res.getFraction(R.fraction.expand_min_display_fraction, 1, 1);
this.mExpandAccelPx = res.getDimension(R.dimen.expand_accel);
this.mCollapseAccelPx = res.getDimension(R.dimen.collapse_accel);
this.mFlingGestureMaxXVelocityPx = res.getDimension(R.dimen.fling_gesture_max_x_velocity);
this.mFlingGestureMaxOutputVelocityPx = res.getDimension(R.dimen.fling_gesture_max_output_velocity);
this.mPeekHeight = (((float) getPaddingBottom()) + res.getDimension(R.dimen.peek_height)) - ((float) (this.mHandleView == null ? 0 : this.mHandleView.getPaddingTop()));
}
示例12: attachToRecyclerView
import android.content.res.Resources; //導入方法依賴的package包/類
public void attachToRecyclerView(@Nullable RecyclerView recyclerView) {
if (this.mRecyclerView != recyclerView) {
if (this.mRecyclerView != null) {
destroyCallbacks();
}
this.mRecyclerView = recyclerView;
if (this.mRecyclerView != null) {
Resources resources = recyclerView.getResources();
this.mSwipeEscapeVelocity = resources.getDimension(R.dimen.item_touch_helper_swipe_escape_velocity);
this.mMaxSwipeVelocity = resources.getDimension(R.dimen.item_touch_helper_swipe_escape_max_velocity);
setupCallbacks();
}
}
}
示例13: CirclePageIndicator
import android.content.res.Resources; //導入方法依賴的package包/類
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.mPaintPageFill = new Paint(1);
this.mPaintStroke = new Paint(1);
this.mPaintFill = new Paint(1);
this.mLastMotionX = -1.0f;
this.mActivePointerId = -1;
if (!isInEditMode()) {
Resources res = getResources();
int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
float defaultStrokeWidth = res.getDimension(R.dimen
.default_circle_indicator_stroke_width);
float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator,
defStyle, 0);
this.mCentered = a.getBoolean(2, defaultCentered);
this.mOrientation = a.getInt(0, defaultOrientation);
this.mPaintPageFill.setStyle(Style.FILL);
this.mPaintPageFill.setColor(a.getColor(5, defaultPageColor));
this.mPaintStroke.setStyle(Style.STROKE);
this.mPaintStroke.setColor(a.getColor(8, defaultStrokeColor));
this.mPaintStroke.setStrokeWidth(a.getDimension(3, defaultStrokeWidth));
this.mPaintFill.setStyle(Style.FILL);
this.mPaintFill.setColor(a.getColor(4, defaultFillColor));
this.mRadius = a.getDimension(6, defaultRadius);
this.mSnap = a.getBoolean(7, defaultSnap);
Drawable background = a.getDrawable(1);
if (background != null) {
setBackgroundDrawable(background);
}
a.recycle();
this.mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(ViewConfiguration
.get(context));
}
}
示例14: HolographicOutlineHelper
import android.content.res.Resources; //導入方法依賴的package包/類
private HolographicOutlineHelper(Context context) {
Resources res = context.getResources();
float mediumBlur = res.getDimension(R.dimen.blur_size_medium_outline);
mMediumOuterBlurMaskFilter = new BlurMaskFilter(mediumBlur, BlurMaskFilter.Blur.OUTER);
mMediumInnerBlurMaskFilter = new BlurMaskFilter(mediumBlur, BlurMaskFilter.Blur.NORMAL);
mThinOuterBlurMaskFilter = new BlurMaskFilter(
res.getDimension(R.dimen.blur_size_thin_outline), BlurMaskFilter.Blur.OUTER);
mShadowBitmapShift = res.getDimension(R.dimen.blur_size_click_shadow);
mShadowBlurMaskFilter = new BlurMaskFilter(mShadowBitmapShift, BlurMaskFilter.Blur.NORMAL);
mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
}
示例15: initDefaultAttrs
import android.content.res.Resources; //導入方法依賴的package包/類
private void initDefaultAttrs(Context context) {
Resources resources = context.getResources();
underlineReductionScale = DEFAULT_REDUCTION_SCALE;
underlineStrokeWidth = resources.getDimension(R.dimen.underline_stroke_width);
underlineBaseColor = ContextCompat.getColor(context, R.color.underline_base_color);
underlineFilledColor = ContextCompat.getColor(context, R.color.underline_filled_color);
underlineCursorColor = ContextCompat.getColor(context, R.color.underline_cursor_color);
underlineSelectedColor = ContextCompat.getColor(context, R.color.underline_selected_color);
textSize = resources.getDimension(R.dimen.code_text_size);
textColor = ContextCompat.getColor(context, R.color.text_main_color);
codeLength = DEFAULT_CODE_LENGTH;
codeHiddenMask = DEFAULT_CODE_MASK;
}