本文整理汇总了Java中android.util.DisplayMetrics类的典型用法代码示例。如果您正苦于以下问题:Java DisplayMetrics类的具体用法?Java DisplayMetrics怎么用?Java DisplayMetrics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DisplayMetrics类属于android.util包,在下文中一共展示了DisplayMetrics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.util.DisplayMetrics; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Get device WINDOW size
//The thumbnail will be requested according to the device resolution
// Standard display --> 16:9 & 4:3
DisplayMetrics displaymetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
//define the with and height of the requested thumbnails according to the screen display of the device
WIDTH16_9 = width;
HEIGHT16_9 = (WIDTH16_9 / 16) * 9;
WIDTH4_3 = width / 2;
HEIGHT4_3 = (WIDTH4_3 / 4) * 3;
contributionsList = new ArrayList<>();
displayedVideos = new ArrayList<>();
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_video, container, false);
}
示例2: getScreenSize
import android.util.DisplayMetrics; //导入依赖的package包/类
public static int[] getScreenSize(Context context){
if (screenSize == null || screenSize[0] <= 480 || screenSize[1] <= 800) {//小于该分辨率会显示不全
screenSize = new int[2];
DisplayMetrics dm = new DisplayMetrics();
dm = context.getResources().getDisplayMetrics();
// float density = dm.density; // 屏幕密度(像素比例:0.75/1.0/1.5/2.0)
// int densityDPI = dm.densityDpi; // 屏幕密度(每寸像素:120/160/240/320)
// float xdpi = dm.xdpi;
// float ydpi = dm.ydpi;
// Log.e(TAG + " DisplayMetrics", "xdpi=" + xdpi + "; ydpi=" + ydpi);
// Log.e(TAG + " DisplayMetrics", "density=" + density + "; densityDPI="
// + densityDPI);
screenSize[0] = dm.widthPixels;// 屏幕宽(像素,如:480px)
screenSize[1] = dm.heightPixels;// 屏幕高(像素,如:800px)
}
return screenSize;
}
示例3: onViewCreated
import android.util.DisplayMetrics; //导入依赖的package包/类
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (null != getLoadingTargetView(view)) {
mVaryViewHelperController = new VaryViewHelperController(getLoadingTargetView(view));
}
//获取屏幕密度及宽高
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mScreenDensity = displayMetrics.density;
mScreenHeight = displayMetrics.heightPixels;
mScreenWidth = displayMetrics.widthPixels;
initViewsAndEvents(view, savedInstanceState);
}
示例4: init
import android.util.DisplayMetrics; //导入依赖的package包/类
private void init(Context context, int drawableId, String text, int textColor, String typefacePath) {
reset();
if (drawableId > 0) setMagicSrc(drawableId);
mTextView = mEditMode ? new EditText(context) : new TextView(context);
//不要用LayoutParams.WRAP_CONTENT,否则每次设置文本都会引发requestLayout()
addView(mTextView, new LayoutParams(0, 0));
mTextView.addTextChangedListener(mTextWatcher);
mTextView.setBackgroundResource(0);
mTextView.setPadding(0, 0, 0, 0); //paddings会导致文本的遮盖,对于EditText, 即使将背景置为null, 也还会有padding
mTextView.setTextColor(textColor);
mTextView.setGravity(Gravity.CENTER);
if (typefacePath != null) setTextFont(typefacePath.startsWith("asset:"), typefacePath);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
//mUnitInPx = (int)(displayMetrics.density * 2 + 0.5f);
//if (!mEditMode) mUnitInPx *= 2;
if (mMinTextSize <= 0) mMinTextSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 9, displayMetrics);
if (mMaxTextSize <= 0) mMaxTextSize = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 80, displayMetrics);
if (mMinTextSize > mMaxTextSize) throw new IllegalArgumentException("字号范围设置错误:[" + mMinTextSize + ", " + mMaxTextSize + "]");
scaleTextSize(1);
mTextSize = mMinTextSizeScaled;
setTextSize(mTextSize);
setText(text);
}
示例5: decodeSampledBitmapFromStream
import android.util.DisplayMetrics; //导入依赖的package包/类
private Bitmap decodeSampledBitmapFromStream(Uri imageUri, int reqWidth,
int reqHeight) throws IOException {
InputStream is = getUriAsStream(imageUri);
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = false;
options.outHeight = reqHeight;
options.outWidth = reqWidth;
options.inPreferQualityOverSpeed = false;
options.inDensity = DisplayMetrics.DENSITY_LOW;
options.inTempStorage = new byte[7680016];
Log.d(this.getClass().getName(),
"displaying image size width, height, inSampleSize "
+ options.outWidth + "," + options.outHeight + ","
+ options.inSampleSize);
Log.d(this.getClass().getName(), "free meomory before image load: "
+ Runtime.getRuntime().freeMemory());
Bitmap bitmap = BitmapFactory.decodeStream(new FlushedInputStream(is),
null, options);
Log.d(this.getClass().getName(), "free meomory after image load: "
+ Runtime.getRuntime().freeMemory());
return bitmap;
}
示例6: setParams
import android.util.DisplayMetrics; //导入依赖的package包/类
private void setParams(Context context, WindowManager.LayoutParams lay) {
DisplayMetrics dm = new DisplayMetrics();
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(dm);
Rect rect = new Rect();
View view = getWindow().getDecorView();
view.getWindowVisibleDisplayFrame(rect);
lay.width = dm.widthPixels;
}
示例7: SimulationView
import android.util.DisplayMetrics; //导入依赖的package包/类
public SimulationView(Context context) {
super(context);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mXDpi = metrics.xdpi;
mYDpi = metrics.ydpi;
mMetersToPixelsX = mXDpi / 0.0254f;
mMetersToPixelsY = mYDpi / 0.0254f;
// rescale the ball so it's about 0.5 cm on screen
Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
final int dstWidth = (int) (sBallDiameter * mMetersToPixelsX + 0.5f);
final int dstHeight = (int) (sBallDiameter * mMetersToPixelsY + 0.5f);
mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);
Options opts = new Options();
opts.inDither = true;
opts.inPreferredConfig = Bitmap.Config.RGB_565;
mWood = BitmapFactory.decodeResource(getResources(), R.drawable.wood, opts);
}
示例8: setSize
import android.util.DisplayMetrics; //导入依赖的package包/类
/**
* One of DEFAULT, or LARGE.
*/
public void setSize(int size) {
if (size != MaterialProgressDrawable.LARGE && size != MaterialProgressDrawable.DEFAULT) {
return;
}
final DisplayMetrics metrics = getResources().getDisplayMetrics();
if (size == MaterialProgressDrawable.LARGE) {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER_LARGE * metrics.density);
} else {
mCircleHeight = mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
}
// force the bounds of the progress circle inside the circle view to
// update by setting it to null before updating its size and then
// re-setting it
mCircleView.setImageDrawable(null);
mProgress.updateSizes(size);
mCircleView.setImageDrawable(mProgress);
}
示例9: ColorView
import android.util.DisplayMetrics; //导入依赖的package包/类
public ColorView(Context context, int resourceLabel, boolean square) {
super(context);
mSquare = square;
mResourceLabel = resourceLabel;
mNumberFormatter = NumberFormat.getIntegerInstance(getContext().getResources().getConfiguration().locale);
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
mTextPaint = new Paint();
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize((int) (metrics.density * FONT_SIZE_DP + 0.5f));
mTextPaint.setColor(0xFFFFFFFF);
mTextPaint.setTextAlign(Paint.Align.CENTER);
mShadowPaint = new Paint(mTextPaint);
mShadowPaint.setStyle(Paint.Style.STROKE);
mShadowPaint.setStrokeCap(Paint.Cap.ROUND);
mShadowPaint.setStrokeJoin(Paint.Join.ROUND);
mShadowPaint.setStrokeWidth(4f);
mShadowPaint.setColor(0xFF000000);
int marginPx = (int) (MARGIN_DP * metrics.density + 0.5f);
setPadding(marginPx, marginPx, marginPx, marginPx);
}
示例10: switchLanguage
import android.util.DisplayMetrics; //导入依赖的package包/类
protected void switchLanguage(String lang) {
Resources resources = getResources();
Configuration configuration = resources.getConfiguration();
DisplayMetrics displayMetrics = resources.getDisplayMetrics();
switch (lang) {
case "zh":
configuration.locale = Locale.TAIWAN;
break;
case "ja":
configuration.locale = Locale.JAPAN;
break;
default:
configuration.locale = Locale.ENGLISH;
break;
}
resources.updateConfiguration(configuration, displayMetrics);
MainApplication.writeSetting("uiLang", lang);
//*
getActivity().finish();
getActivity().startActivity(getActivity().getIntent());
//*/
}
示例11: init
import android.util.DisplayMetrics; //导入依赖的package包/类
private void init(Context context) {
DisplayMetrics metrics = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metrics);
mScreenHeight = metrics.heightPixels;
mHeaderContainer = new FrameLayout(context);
mHeaderImage = new ImageView(context);
int width = metrics.widthPixels;
setHeaderViewSize(width, (int) ((((float) width) / 16.0f) * 9.0f));//Screen Ratio = 16:9
mShadow = new ImageView(context);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.BOTTOM;
mShadow.setLayoutParams(params);
mHeaderContainer.addView(mHeaderImage);
mHeaderContainer.addView(mShadow);
addHeaderView(mHeaderContainer);
super.setOnScrollListener(this);
}
示例12: getNotificationImageSize
import android.util.DisplayMetrics; //导入依赖的package包/类
public static int getNotificationImageSize(Context context)
{
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
int imageSizeLarge = Math.round(Math.min(metrics.widthPixels, metrics.heightPixels));
int size;
if (imageSizeLarge <= 480)
{
size = 64;
}
else size = imageSizeLarge <= 768 ? 128 : 256;
return size;
}
示例13: resize
import android.util.DisplayMetrics; //导入依赖的package包/类
public void resize(int spanCount) {
int approximateWidth = 300;
int approximateHeight = 400;
DisplayMetrics displayMetrics = itemView.getContext().getResources().getDisplayMetrics();
int screenWidth = displayMetrics.widthPixels;
int width = screenWidth / spanCount;
int height = (approximateHeight * width) / approximateWidth;
ViewGroup.LayoutParams params = itemView.getLayoutParams();
params.width = width;
params.height = height;
itemView.setLayoutParams(params);
itemView.invalidate();
}
示例14: initAttrs
import android.util.DisplayMetrics; //导入依赖的package包/类
/**
* 获取自定义attrs
*/
private void initAttrs(AttributeSet attrs) {
DisplayMetrics dm = getResources().getDisplayMetrics();
this.textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSize, dm);
this.intervalValue = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, intervalValue, dm);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.IndicatorView);
this.markerId = typedArray.getResourceId(R.styleable.IndicatorView_marker, R.drawable.ic_vector_indicator_down);
this.marker = drawableToBitmap(createVectorDrawable(markerId, R.color.indicator_color_1));
this.indicatorValue = typedArray.getInt(R.styleable.IndicatorView_indicatorValue, indicatorValue);
this.textSize = typedArray.getDimensionPixelSize(R.styleable.IndicatorView_textSize, textSize);
this.intervalValue = typedArray.getDimensionPixelSize(R.styleable.IndicatorView_intervalSize, intervalValue);
this.textColor = typedArray.getColor(R.styleable.IndicatorView_textColor, getResources().getColor(textColorId));
this.indicatorStringsResourceId = typedArray.getInt(R.styleable.IndicatorView_indicatorStrings, indicatorStringsResourceId);
this.indicatorColorsResourceId = typedArray.getInt(R.styleable.IndicatorView_indicatorColors, indicatorColorsResourceId);
typedArray.recycle();
}
示例15: resetDensity
import android.util.DisplayMetrics; //导入依赖的package包/类
public synchronized static void resetDensity(Context context) {
if (context != null && null != context.getResources()) {
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
sDensity = metrics.density;
sFontDensity = metrics.scaledDensity;
sDensityDpi = metrics.densityDpi;
sScaleX = getScreenWidth(context)/sDefaultWidth;
sScaleY = getScreenHeight(context)/sDefaultHeight;
try {
final ViewConfiguration configuration = ViewConfiguration.get(context);
if (null != configuration) {
sTouchSlop = configuration.getScaledTouchSlop();
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}