Java 类android.util.DisplayMetrics 实例源码
项目:APIJSON-Android-RxJava
文件:ScreenUtil.java
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;
}
项目:redpacketui-open
文件:RPBaseFragment.java
@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);
}
项目:CommonsLab
文件:VideoFragment.java
@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);
}
项目:QMark
文件:MagicBoardView.java
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);
}
项目:yaacc-code
文件:RetrieveImageTask.java
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;
}
项目:buildAPKsSamples
文件:AccelerometerPlayActivity.java
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);
}
项目:GeekZone
文件:SwipeRefreshLayout.java
/**
* 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);
}
项目:GitHub
文件:ColorsActivity.java
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);
}
项目:TaipeiTechRefined
文件:EtcFragment.java
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());
//*/
}
项目:YCEventConflict
文件:PullToZoomListView.java
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);
}
项目:ultrasonic
文件:Util.java
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;
}
项目:AppAuth-OAuth2-Books-Demo
文件:BookListAdapter.java
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();
}
项目:GitHub
文件:IndicatorView.java
/**
* 获取自定义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();
}
项目:GCSApp
文件:BaseView.java
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();
}
}
}
项目:Rudeness
文件:DensityHelper.java
/**
* 重新计算displayMetrics.xhdpi, 使单位pt重定义为设计稿的相对长度
* @see #activate()
*
* @param context
* @param designWidth 设计稿的宽度
*/
private static void resetDensity(Context context, float designWidth){
if(context == null)
return;
Point size = new Point();
((WindowManager)context.getSystemService(WINDOW_SERVICE)).getDefaultDisplay().getSize(size);
Resources resources = context.getResources();
resources.getDisplayMetrics().xdpi = size.x/designWidth*72f;
//解决MIUI更改框架导致的MIUI7+Android5.1.1上出现的失效问题(以及极少数基于这部分miui去掉art然后置入xposed的手机)
if("MiuiResources".equals(resources.getClass().getSimpleName()) || "XResources".equals(resources.getClass().getSimpleName())){
try {
Field field = Resources.class.getDeclaredField("mTmpMetrics");
field.setAccessible(true);
DisplayMetrics metrics = (DisplayMetrics) field.get(resources);
metrics.xdpi = size.x/designWidth*72f;
} catch (Exception e) {
e.printStackTrace();
}
}
}
项目:Tribe
文件:EditLifeFragment.java
private void initPhotoDialog(){
mDialog = new Dialog(getContext(),R.style.DialogStyle);
mDialogView = LayoutInflater.from(getContext()).inflate(R.layout.take_photo_dialog,null);
mChoosePhoto = mDialogView.findViewById(R.id.choosePhoto);
mTakePhoto = mDialogView.findViewById(R.id.takePhoto);
mChoosePhoto.setOnClickListener(this);
mTakePhoto.setOnClickListener(this);
mDialog.setContentView(mDialogView);
Window window = mDialog.getWindow();
window.setGravity(Gravity.BOTTOM);
WindowManager.LayoutParams layoutParams = window.getAttributes();
WindowManager manager = getActivity().getWindowManager();
DisplayMetrics displayMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(displayMetrics);
layoutParams.width = displayMetrics.widthPixels;
window.setAttributes(layoutParams);
}
项目:nightmode
文件:Utility.java
public static int getTrueScreenHeight(Context context) {
int dpi = 0;
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DisplayMetrics dm = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealMetrics(dm);
dpi = dm.heightPixels;
} else {
try {
Class c = Class.forName("android.view.Display");
Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
method.invoke(display, dm);
dpi = dm.heightPixels;
} catch (Exception e) {
e.printStackTrace();
}
}
return dpi;
}
项目:CXJPadProject
文件:BasicPopup.java
public BasicPopup(Activity activity) {
this.activity = activity;
DisplayMetrics metrics = ScreenUtils.displayMetrics(activity);
screenWidthPixels = metrics.widthPixels;
screenHeightPixels = metrics.heightPixels;
initDialog();
}
项目:HeroVideo-master
文件:MediaPlayer.java
public float pixel2dip(Context context, float n){
Resources resources = context.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
float dp = n / (metrics.densityDpi / 160f);
return dp;
}
项目:buildAPKsSamples
文件:InsertionListView.java
/**
* Returns the absolute x,y coordinates of the view relative to the top left
* corner of the phone screen.
*/
public Point getLocationOnScreen(View v) {
DisplayMetrics dm = new DisplayMetrics();
((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
int[] location = new int[2];
v.getLocationOnScreen(location);
return new Point(location[0], location[1]);
}
项目:FaceAI_Android
文件:VideoRecognise.java
private void setSurfaceSize() {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = (int) (width * PREVIEW_WIDTH / (float) PREVIEW_HEIGHT);
LayoutParams params = new LayoutParams(width, height);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mPreviewSurface.setLayoutParams(params);
mFaceSurface.setLayoutParams(params);
}
项目:EmotionApp
文件:ScreenUtils.java
/**
* 获得屏幕高度
*
* @param context
* @return
*/
public static int getScreenHeight(Context context)
{
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
}
项目:empty-state-recyclerview
文件:CardContentLoadingState.java
CardContentLoadingState(Context c) {
super(c);
setNumberOfContentItems(2);
DisplayMetrics dm = c.getResources().getDisplayMetrics();
this.large = (int)(16f * dm.density);
// Setup list content item defaults
this.circleSize = (int)(40f * dm.density);
this.lineHeight = (int)(12f * dm.density);
}
项目:EasyAndroid
文件:ScreenTool.java
/**
* 获取屏幕DisplayMetrics
*
* @return DisplayMetrics
*/
public static DisplayMetrics getDisplayMetrics()
{
WindowManager windowManager = Managers.getWindowManager();
// 创建了一张白纸
DisplayMetrics dm = new DisplayMetrics();
// 给白纸设置宽高
windowManager.getDefaultDisplay().getMetrics(dm);
return dm;
}
项目:TitleLayout
文件:ScreenUtil.java
/**
* 获取当前屏幕截图,包含状态栏
*
* @param activity activity
* @return Bitmap
*/
public static Bitmap captureWithStatusBar(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
DisplayMetrics dm = new DisplayMetrics();
activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
Bitmap ret = Bitmap.createBitmap(bmp, 0, 0, dm.widthPixels, dm.heightPixels);
view.destroyDrawingCache();
return ret;
}
项目:FireFiles
文件:MaterialProgressDrawable.java
private void setSizeParameters(double progressCircleWidth, double progressCircleHeight,
double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
}
项目:OffsetAnimator
文件:ScreenUtils.java
public static int getScreenHeight(Context context) {
if (context == null) return 0;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}
项目:AndroidOpen
文件:SwipeToRefreshLayout.java
public SwipeToRefreshLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
setWillNotDraw(false);
mDecelerateInterpolator = new DecelerateInterpolator(2f);
// 默认下拉刷新
mType = SwipeToRefreshLayoutType.TOP;
mBothType = false;
final DisplayMetrics metrics = getResources().getDisplayMetrics();
mCircleLoadingSize = (int) (40 * metrics.density);
initLoadingView();
ViewCompat.setChildrenDrawingOrderEnabled(this, true);
mSpinnerFinalOffset = 64 * metrics.density;
mTotalDragDistance = mSpinnerFinalOffset;
}
项目:Shot
文件:ScreenshotTest.java
protected void compareScreenshot(View view, int height) {
Context context = getInstrumentation().getTargetContext();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics metrics = new DisplayMetrics();
windowManager.getDefaultDisplay().getMetrics(metrics);
ViewHelpers.setupView(view)
.setExactHeightPx(context.getResources().getDimensionPixelSize(height))
.setExactWidthPx(metrics.widthPixels)
.layout();
Screenshot.snap(view).record();
}
项目:SciChart.Android.Examples
文件:CustomizationCursorModifierTooltipsFragment.java
public CustomXySeriesTooltip(Context context, XySeriesInfo seriesInfo) {
super(context, seriesInfo);
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
final int padding = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1f, displayMetrics));
this.setPadding(padding, padding, padding, padding);
}
项目:LiuAGeAndroid
文件:SystemBarTintManager.java
@SuppressLint("NewApi")
private float getSmallestWidthDp(Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
} else {
// TODO this is not correct, but we don't really care pre-kitkat
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
float widthDp = metrics.widthPixels / metrics.density;
float heightDp = metrics.heightPixels / metrics.density;
return Math.min(widthDp, heightDp);
}
项目:KUtils-master
文件:SystemBarTintManager.java
@SuppressLint("NewApi")
private float getSmallestWidthDp(Activity activity) {
DisplayMetrics metrics = new DisplayMetrics();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
} else {
// TODO this is not correct, but we don't really care pre-kitkat
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
}
float widthDp = metrics.widthPixels / metrics.density;
float heightDp = metrics.heightPixels / metrics.density;
return Math.min(widthDp, heightDp);
}
项目:BaseCore
文件:ScreenUtils.java
/**
* 获取屏幕的宽度(单位:px)
*
* @return 屏幕宽px
*/
public static int getScreenWidth() {
WindowManager windowManager = (WindowManager) Utils.getContext().getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();// 创建了一张白纸
windowManager.getDefaultDisplay().getMetrics(dm);// 给白纸设置宽高
return dm.widthPixels;
}
项目:RefreshLoadLayout
文件:MaterialProgressDrawable.java
void setSizeParameters(double progressCircleWidth, double progressCircleHeight,
double centerRadius, double strokeWidth, float arrowWidth, float arrowHeight) {
final Ring ring = mRing;
final DisplayMetrics metrics = mResources.getDisplayMetrics();
final float screenDensity = metrics.density;
mWidth = progressCircleWidth * screenDensity;
mHeight = progressCircleHeight * screenDensity;
ring.setStrokeWidth((float) strokeWidth * screenDensity);
ring.setCenterRadius(centerRadius * screenDensity);
ring.setColorIndex(0);
ring.setArrowDimensions(arrowWidth * screenDensity, arrowHeight * screenDensity);
ring.setInsets((int) mWidth, (int) mHeight);
}
项目:CXJPadProject
文件:SobotSelectPicDialog.java
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;
}
项目:AndroidDevSamples
文件:ScreenUtil.java
/**
* @return 获取屏幕真实分辨率
*/
public static Point getAvailableResolution(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
Point point = new Point();
point.x = outMetrics.widthPixels;
point.y = outMetrics.heightPixels;
return point;
}
项目:VanGogh
文件:ScreenUtils.java
/**
* 获得屏幕高度
*
* @param context
* @return
*/
public static int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics displayMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(displayMetrics);
return displayMetrics.heightPixels;
}
项目:CXJPadProject
文件:ClearHistoryDialog.java
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();
if(getWindow() != null){
View view = getWindow().getDecorView();
view.getWindowVisibleDisplayFrame(rect);
lay.width = dm.widthPixels;
}
}
项目:FakeWeather
文件:SizeUtils.java
public static int getScreenWidth(Context context) {
if (screenWidth != 0)
return screenWidth;
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics dm = new DisplayMetrics();// 创建了一张白纸
windowManager.getDefaultDisplay().getMetrics(dm);// 给白纸设置宽高
screenWidth = dm.widthPixels;
return screenWidth;
}
项目:javaide
文件:DimensionConverter.java
public static int stringToDimensionPixelSize(String dimension, DisplayMetrics metrics, ViewGroup parent, boolean horizontal) {
if (dimension.endsWith("%")) {
float pct = Float.parseFloat(dimension.substring(0, dimension.length() - 1)) / 100.0f;
return (int) (pct * (horizontal ? parent.getMeasuredWidth() : parent.getMeasuredHeight()));
}
return stringToDimensionPixelSize(dimension, metrics);
}