本文整理汇总了Java中android.view.Display.getHeight方法的典型用法代码示例。如果您正苦于以下问题:Java Display.getHeight方法的具体用法?Java Display.getHeight怎么用?Java Display.getHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Display
的用法示例。
在下文中一共展示了Display.getHeight方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getScreenSize
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕尺寸
*/
@SuppressLint("ObsoleteSdkInt")
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static Point getScreenSize() {
WindowManager windowManager = (WindowManager) sContext.getSystemService(Context.WINDOW_SERVICE);
Display display = null;
if (windowManager != null) {
display = windowManager.getDefaultDisplay();
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
if (display != null) {
return new Point(display.getWidth(), display.getHeight());
} else {
return null;
}
} else {
Point point = new Point();
if (display != null) {
display.getSize(point);
}
return point;
}
}
示例2: init
import android.view.Display; //导入方法依赖的package包/类
protected void init(Context context, AttributeSet attributeSet) {
mColorNormal = getColor(android.R.color.holo_blue_dark);
mColorPressed = getColor(android.R.color.holo_blue_light);
mIcon = 0;
mSize = SIZE_NORMAL;
if (attributeSet != null) {
initAttributes(context, attributeSet);
}
mCircleSize = getCircleSize(mSize);
mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
mDrawableSize = (int) (mCircleSize + 2 * mShadowRadius);
//point size overhead
WindowManager mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = mWindowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
display.getSize(size);
mYHidden = size.y;
} else mYHidden = display.getHeight();
updateBackground();
}
示例3: initFromCameraParameters
import android.view.Display; //导入方法依赖的package包/类
/**
* Reads, one time, values from the camera that are needed by the app.
*/
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
previewFormat = parameters.getPreviewFormat();
previewFormatString = parameters.get("preview-format");
Log.d(TAG, "Default preview format: " + previewFormat + '/' + previewFormatString);
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
screenResolution = new Point(display.getWidth(), display.getHeight());
Log.d(TAG, "Screen resolution: " + screenResolution);
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
}
// 下句第二参数要根据竖屏修改
cameraResolution = getCameraResolution(parameters, screenResolutionForCamera);
//cameraResolution = getCameraResolution(parameters, screenResolution);
Log.d(TAG, "Camera resolution: " + screenResolution);
}
示例4: onCreate
import android.view.Display; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle bundle, @NonNull MasterSecret masterSecret) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 1.0f;
params.dimAmount = 0.1f;
params.gravity = Gravity.TOP;
getWindow().setAttributes(params);
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if (height > width) getWindow().setLayout((int) (width * .85), (int) (height * .5));
else getWindow().setLayout((int) (width * .7), (int) (height * .75));
super.onCreate(bundle, masterSecret);
titleView.setOnClickListener(null);
}
示例5: getScreenWidth
import android.view.Display; //导入方法依赖的package包/类
/**
* Gets screen width
*/
public int getScreenWidth() {
int columnWidth;
WindowManager wm = (WindowManager) _context
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
final Point point = new Point();
try {
display.getSize(point);
} catch (NoSuchMethodError ignore) { // Older device
point.x = display.getWidth();
point.y = display.getHeight();
}
columnWidth = point.x;
return columnWidth;
}
示例6: getScreenSize
import android.view.Display; //导入方法依赖的package包/类
@SuppressLint({"NewApi"})
public static int[] getScreenSize(Context context) {
int[] screenSize = new int[2];
boolean measuredWidth = false;
boolean measuredheight = false;
Point size = new Point();
WindowManager w = (WindowManager) context.getSystemService("window");
int measuredWidth1;
int measuredheight1;
if (Build.VERSION.SDK_INT >= 13) {
w.getDefaultDisplay().getSize(size);
measuredWidth1 = size.x;
measuredheight1 = size.y;
} else {
Display d = w.getDefaultDisplay();
measuredWidth1 = d.getWidth();
measuredheight1 = d.getHeight();
}
screenSize[0] = measuredWidth1;
screenSize[1] = measuredheight1;
return screenSize;
}
示例7: calculateMaxBitmapSize
import android.view.Display; //导入方法依赖的package包/类
protected int calculateMaxBitmapSize() {
int width;
int height;
Display display = ((WindowManager) getContext().getSystemService("window"))
.getDefaultDisplay();
Point size = new Point();
if (VERSION.SDK_INT >= 13) {
display.getSize(size);
width = size.x;
height = size.y;
} else {
width = display.getWidth();
height = display.getHeight();
}
return (int) Math.sqrt(Math.pow((double) width, PathListView.ZOOM_X2) + Math.pow((double)
height, PathListView.ZOOM_X2));
}
示例8: initFromCameraParameters
import android.view.Display; //导入方法依赖的package包/类
/**
* Reads, one time, values from the camera that are needed by the app.
*/
void initFromCameraParameters(Camera camera) {
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
// We're landscape-only, and have apparently seen issues with display thinking it's portrait
// when waking from sleep. If it's not landscape, assume it's mistaken and reverse them:
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
screenResolution = new Point(width, height);
Log.i(TAG, "Screen resolution: " + screenResolution);
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Camera resolution: " + cameraResolution);
}
示例9: getScreenHeight
import android.view.Display; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
public static int getScreenHeight(Context ctx) {
if (screen_height == 0) {
Display screenSize = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
screen_height = screenSize.getHeight();
}
return screen_height;
}
示例10: moveOffScreen
import android.view.Display; //导入方法依赖的package包/类
private void moveOffScreen() {
Display display = getWindowManager().getDefaultDisplay();
int height = display.getHeight(); // deprecated
int offset = (int)(height * 0.65); /* percent to move */
RelativeLayout.LayoutParams rlParams =
(RelativeLayout.LayoutParams)mChart.getLayoutParams();
rlParams.setMargins(0, 0, 0, -offset);
mChart.setLayoutParams(rlParams);
}
示例11: zoomForFilePath
import android.view.Display; //导入方法依赖的package包/类
public static Bitmap zoomForFilePath(Activity context, String filePath) {
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
BitmapFactory.Options opt = new BitmapFactory.Options();
//这个isjustdecodebounds很重要
opt.inJustDecodeBounds = true;
//获取到这个图片的原始宽度和高度
int picWidth = bitmap.getWidth();
int picHeight = bitmap.getHeight();
//获取屏的宽度和高度
WindowManager windowManager = context.getWindowManager();
Display display = windowManager.getDefaultDisplay();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
//isSampleSize是表示对图片的缩放程度,比如值为2图片的宽度和高度都变为以前的1/2
opt.inSampleSize = 1;
//根据屏的大小和图片大小计算出缩放比例
if (picWidth > picHeight) {
if (picWidth > screenWidth)
opt.inSampleSize = picWidth / screenWidth;
} else {
if (picHeight > screenHeight)
opt.inSampleSize = picHeight / screenHeight;
}
//这次再真正地生成一个有像素的,经过缩放了的bitmap
opt.inJustDecodeBounds = false;
bitmap = BitmapFactory.decodeFile(filePath, opt);
return bitmap;
}
示例12: getScaledDrawable
import android.view.Display; //导入方法依赖的package包/类
/**
* Get a BitmapDrawable from a local file that is scaled down
* to fid the current Window size.
*/
@SuppressWarnings("deprecation")
public static BitmapDrawable getScaledDrawable(Activity a, String path) {
Log.d(TAG, "Inside getScaledDrawable()");
Display display = a.getWindowManager().getDefaultDisplay();
float destWidth = display.getWidth();
float destHeight = display.getHeight();
// Read in the dimensions of the image on disk
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
float srcWidth = options.outWidth;
float srcHeight = options.outHeight;
Log.d(TAG, "srcWidth: " + srcWidth);
Log.d(TAG, "srcHeight: " + srcHeight);
int inSampleSize = 1;
if( srcHeight > destHeight || srcWidth > destWidth) {
if(srcWidth > srcHeight){
inSampleSize = Math.round( srcHeight / destHeight );
}
else {
inSampleSize = Math.round(srcWidth / destWidth);
}
}
options = new BitmapFactory.Options();
options.inSampleSize = inSampleSize;
Log.d(TAG, "inSampleSize: " + inSampleSize);
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
return new BitmapDrawable(a.getResources(), bitmap);
}
示例13: getScreenHeight
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕的高度
* @param context
* @return
*/
public static int getScreenHeight(Context context) {
WindowManager manager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
return display.getHeight();
}
示例14: attach
import android.view.Display; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
@Override
public ViewTreeObserver.OnGlobalLayoutListener attach(final Activity activity, IPanelLayout target,
OnKeyboardListener listener) {
final ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
final boolean isFullScreen = ViewUtil.isFullScreen(activity);
final boolean isTranslucentStatus = ViewUtil.isTranslucentStatus(activity);
final boolean isFitSystemWindows = ViewUtil.isFitsSystemWindows(activity);
final Display display = activity.getWindowManager().getDefaultDisplay();
final int screenHeight;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
final Point screenSize = new Point();
display.getSize(screenSize);
screenHeight = screenSize.y;
} else {
screenHeight = display.getHeight();
}
ViewTreeObserver.OnGlobalLayoutListener globalLayoutListener = new KeyboardStatusListener(
isFullScreen,
isTranslucentStatus,
isFitSystemWindows,
contentView,
target,
listener,
screenHeight);
contentView.getViewTreeObserver().addOnGlobalLayoutListener(globalLayoutListener);
return globalLayoutListener;
}
示例15: getScreenSize
import android.view.Display; //导入方法依赖的package包/类
/**
* 获取屏幕尺寸
*/
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static Point getScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR2) {
return new Point(display.getWidth(), display.getHeight());
} else {
Point point = new Point();
display.getSize(point);
return point;
}
}