本文整理了Java中android.view.Window.setGravity()
方法的一些代码示例,展示了Window.setGravity()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Window.setGravity()
方法的具体详情如下:
包路径:android.view.Window
类名称:Window
方法名:setGravity
暂无
代码示例来源:origin: stackoverflow.com
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle b) {
Window window = getDialog().getWindow();
// set "origin" to top left corner, so to speak
window.setGravity(Gravity.TOP|Gravity.LEFT);
// after that, setting values for x and y works "naturally"
WindowManager.LayoutParams params = window.getAttributes();
params.x = 300;
params.y = 100;
window.setAttributes(params);
Log.d(TAG, String.format("Positioning DialogFragment to: x %d; y %d", params.x, params.y));
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
private void initWindowParams() {
Window dialogWindow = getWindow();
// 获取屏幕宽、高用
WindowManager wm = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = (int) (display.getWidth() * 0.65); // 宽度设置为屏幕的0.65
dialogWindow.setGravity(Gravity.CENTER);
dialogWindow.setAttributes(lp);
}
代码示例来源:origin: Naoki2015/CircleDemo
private void initWindowParams() {
Window dialogWindow = getWindow();
// 获取屏幕宽、高用
WindowManager wm = (WindowManager) mContext
.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = (int) (display.getWidth() * 0.65); // 宽度设置为屏幕的0.65
dialogWindow.setGravity(Gravity.CENTER);
dialogWindow.setAttributes(lp);
}
代码示例来源:origin: gzu-liyujiang/AndroidPicker
/**
* 位于屏幕何处
*
* @see Gravity
*/
public void setGravity(int gravity) {
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(gravity);
}
if (gravity == Gravity.CENTER) {
//居于屏幕正中间时,宽度不允许填充屏幕
setWidth((int) (screenWidthPixels * 0.7f));
}
}
代码示例来源:origin: H07000223/FlycoDialog_Master
/** show at location only valid for mIsPopupStyle true(指定位置显示,只对isPopupStyle为true有效) */
public void showAtLocation(int gravity, int x, int y) {
if (mIsPopupStyle) {
Window window = getWindow();
LayoutParams params = window.getAttributes();
window.setGravity(gravity);
params.x = x;
params.y = y;
}
show();
}
代码示例来源:origin: H07000223/FlycoDialog_Master
@Override
protected void onStart() {
super.onStart();
mLlTop.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
mLlTop.setGravity(Gravity.TOP);
getWindow().setGravity(Gravity.TOP);
mLlTop.setPadding(mLeft, mTop, mRight, mBottom);
}
代码示例来源:origin: Bigkoo/Android-PickerView
public void createDialog() {
if (dialogView != null) {
mDialog = new Dialog(context, R.style.custom_dialog2);
mDialog.setCancelable(mPickerOptions.cancelable);//不能点外面取消,也不能点back取消
mDialog.setContentView(dialogView);
Window dialogWindow = mDialog.getWindow();
if (dialogWindow != null) {
dialogWindow.setWindowAnimations(R.style.picker_view_scale_anim);
dialogWindow.setGravity(Gravity.CENTER);//可以改成Bottom
}
mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (onDismissListener != null) {
onDismissListener.onDismiss(BasePickerView.this);
}
}
});
}
}
代码示例来源:origin: H07000223/FlycoDialog_Master
@Override
protected void onStart() {
super.onStart();
mLlTop.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
mLlTop.setGravity(Gravity.BOTTOM);
getWindow().setGravity(Gravity.BOTTOM);
mLlTop.setPadding(mLeft, mTop, mRight, mBottom);
}
代码示例来源:origin: jeasonlzy/NineGridView
Window window = getWindow();
WindowManager.LayoutParams layout = window.getAttributes();
window.setGravity(gravity);
if (width == 0) {
DisplayMetrics dm = new DisplayMetrics();
代码示例来源:origin: gzu-liyujiang/AndroidPicker
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
代码示例来源:origin: WVector/AppUpdate
dialogWindow.setGravity(Gravity.CENTER);
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
代码示例来源:origin: eleme/UETool
public void show(Element element) {
show();
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
dialogWindow.setGravity(Gravity.LEFT | Gravity.TOP);
lp.x = element.getRect().left;
lp.y = element.getRect().bottom;
lp.width = getScreenWidth() - dip2px(30);
lp.height = getScreenHeight() / 2;
dialogWindow.setAttributes(lp);
adapter.notifyDataSetChanged(element);
layoutManager.scrollToPosition(0);
}
代码示例来源:origin: facebook/facebook-android-sdk
getWindow().setGravity(Gravity.CENTER);
代码示例来源:origin: zaaach/CityPicker
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if (mOnPickListener != null){
mOnPickListener.onCancel();
}
}
return false;
}
});
measure();
Window window = dialog.getWindow();
if (window != null) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
window.setGravity(Gravity.BOTTOM);
window.setLayout(width, height - ScreenUtil.getStatusBarHeight(getActivity()));
if (enableAnim) {
window.setWindowAnimations(mAnimStyle);
}
}
}
代码示例来源:origin: Bigkoo/Android-PickerView
if (dialogWindow != null) {
dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
dialogWindow.setDimAmount(0.1f);
代码示例来源:origin: stackoverflow.com
if (progressDialog == null) {
progressDialog = new Dialog(activityRequestingProgressDialog);
progressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
progressDialog.setContentView(R.layout.progress_upload);
progressBar = (ProgressBar) progressDialog.findViewById(R.id.progressBar);
progressText = (TextView) progressDialog.findViewById(R.id.progressText);
progressText.setText("0 %");
progressText.setTextSize(18);
Button buttonCancel = (Button) progressDialog.findViewById(R.id.btnCancel);
buttonCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
cancelProgressDialog();
stopUpload("Upload cancelled.");
}
});
Window window = progressDialog.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.setGravity(Gravity.BOTTOM);
progressDialog.show();
}
progressText.setText(text);
progressBar.setProgress(percent);
代码示例来源:origin: iielse/ImageWatcher
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
window.setGravity(Gravity.BOTTOM);
代码示例来源:origin: Rogero0o/CatLoadingView
mDialog.setContentView(R.layout.catloading_main);
mDialog.setCanceledOnTouchOutside(isClickCancelAble);
mDialog.getWindow().setGravity(Gravity.CENTER);
代码示例来源:origin: TakWolf/CNode-Material-Design
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getWindow() != null) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
getWindow().setGravity(Gravity.BOTTOM);
}
}
代码示例来源:origin: smuyyh/SprintNBA
@Override
protected void onStart() {
super.onStart();
mLlTop.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
mLlTop.setGravity(Gravity.TOP);
getWindow().setGravity(Gravity.TOP);
mLlTop.setPadding(mLeft, mTop, mRight, mBottom);
}
内容来源于网络,如有侵权,请联系作者删除!