我有一个从对话框扩展而来的自定义对话框。 为了在上面放置组件,我需要知道对话框的宽度。我该怎么做? 谢谢
编辑:
public class AnswerTypeDialog extends Dialog{
public AnswerTypeDialog(Context context) {
super(context);
mContext = context;
}
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
protected void init(){
ll=(RelativeLayout) LayoutInflater.from(mContext).inflate(R.layout.answertype_layout, null);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(ll);
mWindowWidth = this.getWindow().getAttributes().width;
}
}
mWindowWidth 为零。
最佳答案
这会起作用。
@Override
public void onWindowFocusChanged (boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
int height=mDialog.getWindow().getDecorView().getHeight();
int width=mDialog.getWindow().getDecorView().getWidth();
}
关于android - 如何在android中获取自定义对话框的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11392334/