Java Code Examples for android.view.Window#setGravity()
The following examples show how to use
android.view.Window#setGravity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StytledDialog.java From DialogUtils with Apache License 2.0 | 6 votes |
public static Dialog showBottomItemDialog(Context context, List<String> words,String bottomTxt, boolean outsideCancleable, boolean cancleable, final MyItemDialogListener listener){ Dialog dialog = buildDialog(context,cancleable,outsideCancleable); int measuredHeight = assignBottomListDialogView(context,dialog,words,bottomTxt,listener); Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.mystyle); setDialogStyle(context,dialog,measuredHeight); dialog.show(); return dialog; }
Example 2
Source File: BaseDialog.java From KrGallery with GNU General Public License v2.0 | 6 votes |
private void initView() { Window window = getWindow(); window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中 window.setWindowAnimations(R.style.bottom_menu_animation); // 添加动画效果 View child = getLayoutInflater().inflate(R.layout.layout_dialog_base, null, false); setContentView(child); mContainer = (FrameLayout) findViewById(R.id.fl_container); mBtnPanel = (FrameLayout) findViewById(R.id.fl_btn_panel); closeIV = (ImageView) findViewById(R.id.iv_close); closeIV.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dismiss(); } }); Window dialogWindow = getWindow(); WindowManager.LayoutParams lp = dialogWindow.getAttributes(); DisplayMetrics d = mContext.getResources().getDisplayMetrics(); // 获取屏幕宽、高用 lp.width = (int) (d.widthPixels * 0.8); // 宽度设置为屏幕的0.9 dialogWindow.setAttributes(lp); setIsCancelable(true); setOnDismissListener(this); }
Example 3
Source File: BasePickerView.java From Android-PickerView with Apache License 2.0 | 6 votes |
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); } } }); } }
Example 4
Source File: DisplayOptionsPopupFragment.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 6 votes |
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.display_options_popup, container); final ViewAnimator viewAnimator = v.findViewById(R.id.settings_view_container); viewAnimator.setDisplayedChild(mCurrentView); Window window = getDialog().getWindow(); if (window != null) { window.setGravity(Gravity.TOP | Gravity.END); // window.setDimAmount(0); window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); //getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); } return v; }
Example 5
Source File: DialogView.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
private void initWindow(double percent, boolean isFromBottom) { if (!isFromBottom) { rootLayout.setBackgroundResource(R.drawable.dialog_common_center_bg); } else { rootLayout.setBackgroundResource(R.drawable.dialog_common_bottom_bg); } Window window = getWindow(); WindowManager.LayoutParams lp = window.getAttributes(); lp.width = (int) (ScreenUtils.getScreenWidth(activity) * percent); lp.height = WindowManager.LayoutParams.WRAP_CONTENT; if (isFromBottom) { window.setGravity(Gravity.BOTTOM); } window.setAttributes(lp); }
Example 6
Source File: McuConfigDialog.java From sealrtc-android with MIT License | 5 votes |
@Override public void onStart() { super.onStart(); Dialog dialog = getDialog(); if (dialog == null) return; dialog.setCancelable(false); dialog.setCanceledOnTouchOutside(false); Window window = dialog.getWindow(); window.setLayout(MATCH_PARENT, WRAP_CONTENT); window.setGravity(Gravity.BOTTOM); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); }
Example 7
Source File: MainActivity.java From DialogUtils with Apache License 2.0 | 5 votes |
private void showDialog() { // AlertDialog dialog = new AlertDialog(this); AppCompatDialog dialog = new AppCompatDialog(this); dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE);//key code to remove title Window window = dialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.mystyle); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//round corner // window.setBackgroundDrawableResource(R.drawable.bg_ios_roundcorner); // window.requestFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_ios_alert_bottom); // AlertDialog.Builder builder = new AlertDialog.Builder(this); // 可以在此设置显示动画 WindowManager.LayoutParams wl = window.getAttributes(); /* wl.x = 0; wl.y = getWindowManager().getDefaultDisplay().getHeight();*/ // 以下这两句是为了保证按钮可以水平满屏 int width = getWindowManager().getDefaultDisplay().getWidth(); // wl.width = ViewGroup.LayoutParams.MATCH_PARENT; wl.width = (int) (width * 0.85); // todo keycode gap wl.height = ViewGroup.LayoutParams.WRAP_CONTENT; //wl.horizontalMargin= 0.2f; // 设置显示位置 // wl.gravity = Gravity.CENTER_HORIZONTAL; dialog.onWindowAttributesChanged(wl); dialog.show(); }
Example 8
Source File: BaseDialog.java From AndroidProject with Apache License 2.0 | 5 votes |
/** * 设置 Dialog 重心 */ public void setGravity(int gravity) { Window window = getWindow(); if (window != null) { window.setGravity(gravity); } }
Example 9
Source File: SelectDialogFragment.java From ksyhttpcache_android with Apache License 2.0 | 5 votes |
private void setDialogPosition(Dialog dialog) { Window window = dialog.getWindow(); window.setGravity(Gravity.CENTER); WindowManager.LayoutParams params = window.getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; params.height = WindowManager.LayoutParams.WRAP_CONTENT; window.setAttributes(params); }
Example 10
Source File: BaseDialog.java From SprintNBA with Apache License 2.0 | 5 votes |
/** 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(); }
Example 11
Source File: SingleWheelPicker.java From RecyclerWheelPicker with Apache License 2.0 | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); Window window = getDialog().getWindow(); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); if (builder.gravity == Gravity.BOTTOM) window.setGravity(Gravity.BOTTOM); View contentView = inflater.inflate(R.layout.dialog_wheel_picker_single, container, false); return contentView; }
Example 12
Source File: ProfileDelegate.java From FastWaiMai with MIT License | 5 votes |
@OnClick(R2.id.tv_profile_gender) public void onViewClickedGender(View view) { mGenderDialog.show(); final Window window = mGenderDialog.getWindow(); if (window != null) { window.setContentView(R.layout.dialog_profile_sex); window.setGravity(Gravity.BOTTOM); if (gender.equals(male)) { ((RadioButton) window.findViewById(R.id.btn_dialog_profile_male)).setChecked(true); } else { ((RadioButton) window.findViewById(R.id.btn_dialog_profile_female)).setChecked(true); } //设置弹出动画 window.setWindowAnimations(R.style.anim_panel_up_from_bottom); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); //设置属性 final WindowManager.LayoutParams params = window.getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; //FLAG_DIM_BEHIND: 窗口之后的内容变暗 FLAG_BLUR_BEHIND: 窗口之后的内容变模糊。 params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND; window.setAttributes(params); ((RadioButton) window.findViewById(R.id.btn_dialog_profile_male)).setOnCheckedChangeListener(this); ((RadioButton) window.findViewById(R.id.btn_dialog_profile_female)).setOnCheckedChangeListener(this); } }
Example 13
Source File: MyDialogBuilder.java From DialogUtil with Apache License 2.0 | 5 votes |
protected ConfigBean buildBottomItemDialog(ConfigBean bean){ IosActionSheetHolder holder = new IosActionSheetHolder(bean.context); bean.viewHolder = holder; bean.dialog.setContentView(holder.rootView); holder.assingDatasAndEvents(bean.context,bean); bean.viewHeight = Tool.mesureHeight(holder.rootView,holder.lv); Window window = bean.dialog.getWindow(); window.setGravity(Gravity.BOTTOM); window.setWindowAnimations(R.style.mystyle); return bean; }
Example 14
Source File: BasicPopup.java From MyBookshelf with GNU General Public License v3.0 | 5 votes |
/** * 位于屏幕何处 * * @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)); } }
Example 15
Source File: KeepLiveActivity.java From Android with MIT License | 5 votes |
@Override public void initView() { activity = this; Window window = getWindow(); window.setGravity(Gravity.LEFT | Gravity.TOP); WindowManager.LayoutParams params = window.getAttributes(); params.x = 0; params.y = 0; params.width = 1; params.height = 1; window.setAttributes(params); receiver =new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { finish(); } }; IntentFilter filter = new IntentFilter(); filter.addAction("KeepLive"); registerReceiver(receiver, filter); }
Example 16
Source File: AbstractDialog.java From Common with Apache License 2.0 | 5 votes |
/** * Creates a dialog window that uses a custom dialog style. * * @param context Context * @param themeResId The dialog's layout resource * @param isSetWin Set the gravity of the window * @param gravity The desired gravity constant * @param width The dialog's width * @param height The dialog's height */ protected AbstractDialog(@NonNull Context context, @StyleRes int themeResId, boolean isSetWin, int gravity, int width, int height) { super(context, themeResId); this.mContext = context; this.mRootView = LayoutInflater.from(context).inflate(getLayoutRes(), null); setContentView(this.mRootView); setCanceledOnTouchOutside(true); setCancelable(true); if (isSetWin) { Window dialogWindow = getWindow(); if (dialogWindow != null) { dialogWindow.setWindowAnimations(-1); dialogWindow.setBackgroundDrawableResource(android.R.color.transparent); dialogWindow.getDecorView().setPadding(0, 0, 0, 0); dialogWindow.setGravity(gravity); // Get the current layout param of the dialog WindowManager.LayoutParams p = dialogWindow.getAttributes(); // Set dialog's width p.width = width; // Set dialog's height p.height = height; dialogWindow.setAttributes(p); } } init(this.mRootView); }
Example 17
Source File: BaseDialog.java From dapp-wallet-demo with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); Window window = getDialog().getWindow(); //设置dialog宽度为屏幕75%,高度随内容扩充 if (window != null) { window.setLayout(getDialogWidth(), getDialogHeight()); //去掉dialog原有白色背景 window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setGravity(gravity()); } }
Example 18
Source File: DialogUitls.java From Instagram-Profile-Downloader with MIT License | 5 votes |
public static Dialog infoPopupWithListner(Context context, String message, String buttonName, final View.OnClickListener listener) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog); dialog.getWindow().getAttributes().windowAnimations = R.style.animationdialog; dialog.setCancelable(false); dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); Window window = dialog.getWindow(); window.setGravity(Gravity.CENTER); window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final TextView btnTxt = (TextView) dialog.findViewById(R.id.txtOK); TextView txt = (TextView) dialog.findViewById(R.id.txt); txt.setText(message); btnTxt.setText(buttonName); if (listener != null) { btnTxt.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); listener.onClick(view); } }); } dialog.show(); return dialog; }
Example 19
Source File: BaseDialogFragment.java From AndroidPlayground with MIT License | 5 votes |
@Override public void onStart() { super.onStart(); // without title and title divider // Less dimmed background; see http://stackoverflow.com/q/13822842/56285 Window window = getDialog().getWindow(); WindowManager.LayoutParams params = window.getAttributes(); //CHECKSTYLE:OFF params.dimAmount = getDimAmount(); // dim only a little bit //CHECKSTYLE:ON window.setAttributes(params); window.setLayout(getWidth(), getHeight()); window.setGravity(getGravity()); // Transparent background; see http://stackoverflow.com/q/15007272/56285 // (Needed to make dialog's alpha shadow look good) window.setBackgroundDrawableResource(android.R.color.transparent); final Resources res = getResources(); final int titleDividerId = res.getIdentifier("titleDivider", "id", "android"); if (titleDividerId > 0) { final View titleDivider = getDialog().findViewById(titleDividerId); if (titleDivider != null) { titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent)); } } }
Example 20
Source File: OnePxActivity.java From AndroidKeepLivePractice with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate(): savedInstanceState = [" + savedInstanceState + "]"); instance = new WeakReference<>(this); Window window = getWindow(); window.setGravity(Gravity.TOP | Gravity.LEFT); WindowManager.LayoutParams attributes = window.getAttributes(); attributes.x = 0; attributes.y = 0; attributes.height = 1; attributes.width = 1; window.setAttributes(attributes); }