我正在寻找一种在 XML 布局中设置 DialogFragment 大小的方法。我知道我可以在 onResume() 方法的代码中设置它,但这不是我想要的。有谁知道我该怎么做?
我意识到这里有一些类似的问题,但没有一个有令人满意的答案。
布局看起来有点像这样:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="800dp"
android:layout_height="500dp" >
...
这是 DialogFragment 代码:
public class MyTestDialog extends DialogFragment {
/*
* (non-Javadoc)
* @see android.support.v4.app.DialogFragment#onCreate(android.os.Bundle)
*/
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NO_FRAME, 0);
}
/*
* (non-Javadoc)
* @see android.support.v4.app.Fragment#onResume()
*/
@Override
public void onResume() {
super.onResume();
// just to see the dialog bounds
getDialog().getWindow().setBackgroundDrawableResource(R.drawable.bg_blue);
}
/*
* (non-Javadoc)
* @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.my_layout, container, false);
return v;
}
}