本文整理了Java中android.view.View.getWindowVisibleDisplayFrame()
方法的一些代码示例,展示了View.getWindowVisibleDisplayFrame()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。View.getWindowVisibleDisplayFrame()
方法的具体详情如下:
包路径:android.view.View
类名称:View
方法名:getWindowVisibleDisplayFrame
暂无
代码示例来源:origin: stackoverflow.com
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
... do something here
}
}
});
代码示例来源:origin: cymcsg/UltimateAndroid
/**
* Get height of status bar
* @param activity
* @return
*/
public static int getStatusBarHeight(Activity activity) {
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
return frame.top;
}
代码示例来源:origin: iMeiji/Toutiao
public int getStateBarHeight(Context context) {
Rect rect = new Rect();
Activity activity = (Activity) context;
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
int statusBarHeight = rect.top;
return statusBarHeight;
}
代码示例来源:origin: wangdan/AisenWeiBo
public static int getAppHeight(Activity paramActivity) {
Rect localRect = new Rect();
paramActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
return localRect.height();
}
代码示例来源:origin: mikepenz/MaterialDrawer
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
decorView.getWindowVisibleDisplayFrame(r);
//get screen height and calculate the difference with the useable area from the r
int height = decorView.getContext().getResources().getDisplayMetrics().heightPixels;
int diff = height - r.bottom;
//if it could be a keyboard add the padding to the view
if (diff != 0) {
// if the use-able screen height differs from the total screen height we assume that it shows a keyboard now
//check if the padding is 0 (if yes set the padding for the keyboard)
if (contentView.getPaddingBottom() != diff) {
//set the padding of the contentView for the keyboard
contentView.setPadding(0, 0, 0, diff);
}
} else {
//check if the padding is != 0 (if yes reset the padding)
if (contentView.getPaddingBottom() != 0) {
//reset the padding of the contentView
contentView.setPadding(0, 0, 0, 0);
}
}
}
};
代码示例来源:origin: stackoverflow.com
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB)
{
final View activityRootView = findViewById(R.id.activityRoot);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect r = new Rect();
//r will be populated with the coordinates of your view that area still visible.
activityRootView.getWindowVisibleDisplayFrame(r);
int heightDiff = activityRootView.getRootView().getHeight() - (r.bottom - r.top);
if (heightDiff > 100) { // if more than 100 pixels, its probably a keyboard...
//Hide the keyboard instantly!
if (getCurrentFocus() != null)
{
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}
}
}
});
}
代码示例来源:origin: stackoverflow.com
parentLayout.getWindowVisibleDisplayFrame(r);
代码示例来源:origin: bingoogolapple/BGASwipeBackLayout-Android
/**
* 手机具有底部导航栏时,底部导航栏是否可见
*/
private static boolean isNavigationBarVisible(Activity activity) {
// View decorView = activity.getWindow().getDecorView();
// return (decorView.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) != 2;
boolean show = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Display display = activity.getWindow().getWindowManager().getDefaultDisplay();
Point point = new Point();
display.getRealSize(point);
View decorView = activity.getWindow().getDecorView();
Configuration conf = activity.getResources().getConfiguration();
if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) {
View contentView = decorView.findViewById(android.R.id.content);
if (contentView != null) {
show = (point.x != contentView.getWidth());
}
} else {
Rect rect = new Rect();
decorView.getWindowVisibleDisplayFrame(rect);
show = (rect.bottom != point.y);
}
}
return show;
}
代码示例来源:origin: gzu-liyujiang/AndroidPicker
/**
* 获取状态栏的高,单位为px,参阅:http://blog.csdn.net/a_running_wolf/article/details/50477965
*/
public static int obtainHeight(Context context) {
if (height != 0) {
return height;
}
int result = 80;// px
try {
int dimenResId = obtainDimenResId(context);
result = context.getResources().getDimensionPixelSize(dimenResId);
} catch (Exception e) {
LogUtils.warn(e);
if (context instanceof Activity) {
android.graphics.Rect frame = new android.graphics.Rect();
((Activity) context).getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
result = frame.top;
}
}
LogUtils.verbose("status bar height: " + result + " px");
height = result;
return result;
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
/**
* 获取当前屏幕截图,不包含状态栏(这个方法没测试通过)
*
* @param activity
* @return Bitmap
*/
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bp = null;
bp = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height
- statusBarHeight);
view.destroyDrawingCache();
return bp;
}
}
代码示例来源:origin: Jacksgong/JKeyboardPanelSwitch
actionBarOverlayLayout.getWindowVisibleDisplayFrame(r);
userRootView.getWindowVisibleDisplayFrame(r);
displayHeight = (r.bottom - r.top);
} else {
代码示例来源:origin: stackoverflow.com
rootView.getWindowVisibleDisplayFrame(r);
DisplayMetrics dm = rootView.getResources().getDisplayMetrics();
代码示例来源:origin: stackoverflow.com
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
代码示例来源:origin: jeasonlzy/ImagePicker
@Override
public void onGlobalLayout() {
rect.setEmpty();
rootView.getWindowVisibleDisplayFrame(rect);
int heightDiff = 0;
if (orientation == ORIENTATION_VERTICAL) {
heightDiff = rootView.getHeight() - (rect.bottom - rect.top);
} else if (orientation == ORIENTATION_HORIZONTAL) {
heightDiff = rootView.getWidth() - (rect.right - rect.left);
}
int navigationBarHeight = Utils.hasVirtualNavigationBar(rootView.getContext()) ? Utils.getNavigationBarHeight(rootView.getContext()) : 0;
if (heightDiff >= navigationBarHeight && heightDiff < navigationBarHeight * 2) {
if (!isShowNavigationBar && listener != null) {
listener.onNavigationBarShow(orientation, heightDiff);
}
isShowNavigationBar = true;
} else {
if (isShowNavigationBar && listener != null) {
listener.onNavigationBarHide(orientation);
}
isShowNavigationBar = false;
}
}
代码示例来源:origin: redsolution/xabber-android
@Override
public void onGlobalLayout() {
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int screenHeight = rootView.getRootView().getHeight();
int heightDifference = screenHeight - (r.bottom - r.top);
int resourceId = mContext.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
heightDifference -= mContext.getResources().getDimensionPixelSize(resourceId);
}
if (heightDifference > lessThanKeyboardHeight) {
keyBoardHeight = heightDifference - screenHeightDelta;
setSize(LayoutParams.MATCH_PARENT, keyBoardHeight);
if (!isOpened) {
if (onSoftKeyboardOpenCloseListener != null)
onSoftKeyboardOpenCloseListener.onKeyboardOpen(keyBoardHeight);
}
isOpened = true;
if (pendingOpen) {
showAtBottom();
pendingOpen = false;
}
} else {
screenHeightDelta = heightDifference;
isOpened = false;
if (onSoftKeyboardOpenCloseListener != null)
onSoftKeyboardOpenCloseListener.onKeyboardClose();
}
}
});
代码示例来源:origin: Jacksgong/JKeyboardPanelSwitch
mTargetRootView.getWindowVisibleDisplayFrame(rect);
height = rect.bottom - rect.top;
代码示例来源:origin: ImmortalZ/TransitionHelper
InfoBean<Object> bean = new InfoBean<>();
view.getWindowVisibleDisplayFrame(bean.originRect);
bean.statusBarHeight = bean.originRect.top;
代码示例来源:origin: ZieIony/Carbon
mAnchorView.getWindowVisibleDisplayFrame(windowRect);
int hWindow = windowRect.bottom - windowRect.top;
int wWindow = windowRect.right - windowRect.left;
代码示例来源:origin: pchmn/MaterialChipsInput
/**
* Fade in
*/
public void fadeIn() {
if(getVisibility() == VISIBLE)
return;
// get visible window (keyboard shown)
final View rootView = getRootView();
Rect r = new Rect();
rootView.getWindowVisibleDisplayFrame(r);
int[] coord = new int[2];
mChipsInput.getLocationInWindow(coord);
ViewGroup.MarginLayoutParams layoutParams = (MarginLayoutParams) getLayoutParams();
layoutParams.topMargin = coord[1] + mChipsInput.getHeight();
// height of the keyboard
layoutParams.bottomMargin = rootView.getHeight() - r.bottom;
setLayoutParams(layoutParams);
AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(200);
startAnimation(anim);
setVisibility(VISIBLE);
}
代码示例来源:origin: ZieIony/Carbon
anchorView.getWindowVisibleDisplayFrame(windowRect);
int hWindow = windowRect.bottom - windowRect.top;
int wWindow = windowRect.right - windowRect.left;
内容来源于网络,如有侵权,请联系作者删除!