本文整理匯總了Java中android.content.res.Resources.getFraction方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getFraction方法的具體用法?Java Resources.getFraction怎麽用?Java Resources.getFraction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.res.Resources
的用法示例。
在下文中一共展示了Resources.getFraction方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDefaultKeyboardHeight
import android.content.res.Resources; //導入方法依賴的package包/類
public static int getDefaultKeyboardHeight(final Resources res) {
final DisplayMetrics dm = res.getDisplayMetrics();
final float keyboardHeight = res.getDimension(R.dimen.config_default_keyboard_height);
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: 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);
}
示例3: EmojiLayoutParams
import android.content.res.Resources; //導入方法依賴的package包/類
public EmojiLayoutParams(final Resources res) {
final int defaultKeyboardHeight = ResourceUtils.getDefaultKeyboardHeight(res);
final int defaultKeyboardWidth = ResourceUtils.getDefaultKeyboardWidth(res);
mKeyVerticalGap = (int) res.getFraction(R.fraction.config_key_vertical_gap_holo,
defaultKeyboardHeight, defaultKeyboardHeight);
mBottomPadding = (int) res.getFraction(R.fraction.config_keyboard_bottom_padding_holo,
defaultKeyboardHeight, defaultKeyboardHeight);
mTopPadding = (int) res.getFraction(R.fraction.config_keyboard_top_padding_holo,
defaultKeyboardHeight, defaultKeyboardHeight);
mKeyHorizontalGap = (int) (res.getFraction(R.fraction.config_key_horizontal_gap_holo,
defaultKeyboardWidth, defaultKeyboardWidth));
mEmojiCategoryPageIdViewHeight =
(int) (res.getDimension(R.dimen.config_emoji_category_page_id_height));
final int baseheight = defaultKeyboardHeight - mBottomPadding - mTopPadding
+ mKeyVerticalGap;
mEmojiActionBarHeight = baseheight / DEFAULT_KEYBOARD_ROWS
- (mKeyVerticalGap - mBottomPadding) / 2;
mEmojiPagerHeight = defaultKeyboardHeight - mEmojiActionBarHeight
- mEmojiCategoryPageIdViewHeight;
mEmojiPagerBottomMargin = 0;
mEmojiKeyboardHeight = mEmojiPagerHeight - mEmojiPagerBottomMargin - 1;
}
示例4: 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()));
}
示例5: addTrain
import android.content.res.Resources; //導入方法依賴的package包/類
@NonNull
private TrainView addTrain(Rect trainRect, int trainType, FrameLayout frameLayout) {
final int size = Math.min(trainRect.width(), trainRect.height());
final TrainView trainView = new TrainView(this);
Resources res = getResources();
int trainWidth = (int) (trainRect.width() * 0.70);
int trainHeight = (int) res.getFraction(R.fraction.rail_height_width_fraction, trainWidth, trainWidth);
trainView.setType(trainType);
trainView.setTrainHeight(trainHeight);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(trainWidth, trainHeight);
frameLayout.addView(trainView, lp);
trainView.setX(trainRect.left + (size - trainWidth) / 2);
trainView.setY(trainRect.top + (size - trainHeight) / 2);
return trainView;
}
示例6: getFloatFromFraction
import android.content.res.Resources; //導入方法依賴的package包/類
public static float getFloatFromFraction(final Resources res, final int fractionResId) {
return res.getFraction(fractionResId, 1, 1);
}