本文整理汇总了Java中android.view.Window.setGravity方法的典型用法代码示例。如果您正苦于以下问题:Java Window.setGravity方法的具体用法?Java Window.setGravity怎么用?Java Window.setGravity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.Window
的用法示例。
在下文中一共展示了Window.setGravity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: AddressPicker
import android.view.Window; //导入方法依赖的package包/类
public AddressPicker(Context context) {
super(context, R.style.transparentWindowStyle);
this.context = context;
view=View.inflate(context,R.layout.layout_address_picker,null);
initCityData();
initView();
initData();
setListener();
this.setContentView(view);
this.setCanceledOnTouchOutside(true);
//从底部弹出
Window window = this.getWindow();
window.setGravity(Gravity.BOTTOM); //此处可以设置dialog显示的位置
window.setWindowAnimations(R.style.windowAnimationStyle); //添加动画
WindowManager.LayoutParams params = window.getAttributes();
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(params);
}
示例2: beginCameraDialog
import android.view.Window; //导入方法依赖的package包/类
final void beginCameraDialog() {
DIALOG.show();
final Window window = DIALOG.getWindow();
if (window != null) {
window.setContentView(R.layout.dialog_camera_panel);
window.setGravity(Gravity.BOTTOM);
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;
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(params);
window.findViewById(R.id.photodialog_btn_cancel).setOnClickListener(this);
window.findViewById(R.id.photodialog_btn_take).setOnClickListener(this);
window.findViewById(R.id.photodialog_btn_native).setOnClickListener(this);
}
}
示例3: initDialog
import android.view.Window; //导入方法依赖的package包/类
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
//contentLayout.setFitsSystemWindows(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(false);//触摸屏幕取消窗体
dialog.setCancelable(false);//按返回键取消窗体
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);
}
示例4: show
import android.view.Window; //导入方法依赖的package包/类
/**
* DialogLoading loading = new DialogLoading(context)
* loading.show("123")
*
* @param msg 消息
*/
public AlertDialog show(String msg) {
alertDialog = new AlertDialog.Builder(mContext).create();
alertDialog.show();
Window window = alertDialog.getWindow();
window.setContentView(R.layout.dialog_loading);
window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
//window.setWindowAnimations(R.style.DialogAnimation);
window.setBackgroundDrawableResource(R.color.transparent);
window.setDimAmount(0f);//覆盖成透明度
this.msg = (TextView) window.findViewById(R.id.textView1);
this.msg.setText(msg);
//alertDialog.setCancelable(false);// 点击退出
return alertDialog;
}
示例5: onCreateView
import android.view.Window; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.item_highlight, container);
v.findViewById(R.id.page_part_number).setVisibility(View.GONE);
v.findViewById(R.id.date_time).setVisibility(View.GONE);
Dialog dialog = getDialog();
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
window.requestFeature(Window.FEATURE_NO_TITLE);
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
return v;
}
示例6: onCreateView
import android.view.Window; //导入方法依赖的package包/类
@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;
}
示例7: initPhotoDialog
import android.view.Window; //导入方法依赖的package包/类
/**
* 初始化选择相册对话框
*/
private void initPhotoDialog(){
mPhotoDialog=new Dialog(this,R.style.DialogStyle);
mPhotoDialogView= LayoutInflater.from(this).inflate(R.layout.take_photo_dialog,null);
mChoosePhoto=(TextView)mPhotoDialogView.findViewById(R.id.choosePhoto);
mTakePhoto=(TextView)mPhotoDialogView.findViewById(R.id.takePhoto);
mChoosePhoto.setOnClickListener(this);
mTakePhoto.setOnClickListener(this);
mPhotoDialog.setContentView(mPhotoDialogView);
Window window=mPhotoDialog.getWindow();
window.setGravity(Gravity.BOTTOM);
WindowManager.LayoutParams lp=window.getAttributes();
WindowManager manager =this.getWindowManager();
DisplayMetrics outMetrics = new DisplayMetrics();
manager.getDefaultDisplay().getMetrics(outMetrics);
lp.width = outMetrics.widthPixels;//宽度为屏幕的x分辨率
window.setAttributes(lp);
}
示例8: onCreate
import android.view.Window; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ddh_sm_dialog_three_options);
findViews();
Window window = getWindow();
window.setBackgroundDrawableResource(android.R.color.transparent);
window.setGravity(Gravity.BOTTOM);
window.setWindowAnimations(R.style.ddh_sm_BottomDialogStyle);
}
示例9: buildBottomDialog
import android.view.Window; //导入方法依赖的package包/类
public static AlertDialog buildBottomDialog(Activity activity, View contentView) {
AlertDialog dialog = new Builder(activity).create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
dialog.setContentView(contentView);
Window dialogWindow = dialog.getWindow();
Display d = activity.getWindowManager().getDefaultDisplay();
LayoutParams p = dialogWindow.getAttributes();
p.width = d.getWidth();
dialogWindow.setAttributes(p);
dialogWindow.setGravity(80);
return dialog;
}
示例10: initWindowParams
import android.view.Window; //导入方法依赖的package包/类
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);
dialogWindow.setGravity(Gravity.CENTER);
dialogWindow.setAttributes(lp);
}
示例11: beginCameraDialog
import android.view.Window; //导入方法依赖的package包/类
/**
* 开启选择拍照还是从相册取照片的对话框
*/
final void beginCameraDialog(){
DIALOG.show();
//获取window,方便设置属性
final Window window = DIALOG.getWindow();
if(window != null){
//设置dialog的自定义布局
window.setContentView(R.layout.dialog_camera_panel);
//设置dialog在底部
window.setGravity(Gravity.BOTTOM);
//设置动画
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;
//弹出对话框背景为灰色
params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
params.dimAmount = 0.5f;
window.setAttributes(params);
//设置按钮点击事件
window.findViewById(R.id.btn_dialog_cancel).setOnClickListener(this);
window.findViewById(R.id.btn_dialog_take_photo).setOnClickListener(this);
window.findViewById(R.id.btn_dialog_pick_photo).setOnClickListener(this);
}
}
示例12: show
import android.view.Window; //导入方法依赖的package包/类
@Override
public void show() {
Window dialogWindow =getWindow();
LayoutParams lp = dialogWindow.getAttributes();
dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.TOP);
WindowManager m = mContext.getWindowManager();
Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
lp.width = (int) (d.getWidth() * 0.8);
lp.y = 80; // 新位置Y坐标
dialogWindow.setAttributes(lp);
super.show();
}
示例13: setupWindow
import android.view.Window; //导入方法依赖的package包/类
private void setupWindow() {
final Window window = getWindow();
final WindowManager.LayoutParams layoutParams = window.getAttributes();
layoutParams.width = getContext().getResources().getDisplayMetrics().widthPixels;
window.setAttributes(layoutParams);
window.setGravity(Gravity.BOTTOM);
}
示例14: showDialogForView
import android.view.Window; //导入方法依赖的package包/类
private void showDialogForView(View view) {
mDialog = new Dialog(mActivity) {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (!hasFocus) super.dismiss();
}
};
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setCanceledOnTouchOutside(true);
mDialog.addContentView(view,
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mItemSelectedCallback.onItemSelected("");
}
});
Window window = mDialog.getWindow();
if (!DeviceFormFactor.isTablet(mActivity)) {
// On smaller screens, make the dialog fill the width of the screen,
// and appear at the top.
window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
window.setGravity(Gravity.TOP);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
}
mDialog.show();
}
示例15: initWindowParams
import android.view.Window; //导入方法依赖的package包/类
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);
}