DialogFragment设置进出动画和宽高 |
您所在的位置:网站首页 › dialog设置高度 › DialogFragment设置进出动画和宽高 |
在onCreatView中 直接设置 getDialog().getWindow().setWindowAnimations(R.style.animate_dialog);public class AnimateDialog extends DialogFragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //隐藏title getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); //设置dialog的 进出 动画 getDialog().getWindow().setWindowAnimations(R.style.animate_dialog); View view=inflater.inflate(R.layout.layout_dialog, null); return view; } } enter: android:toYDelta="0%p" android:duration="500" xmlns:android="http://schemas.android.com/apk/res/android">out: android:fromYDelta="0%p" android:toYDelta="100%p" android:duration="500" xmlns:android="http://schemas.android.com/apk/res/android"> 在Activity中创建dialogfragment时,指定动画时会报错: AnimateDialog animateDialog=new AnimateDialog(); //会报null,不能这样设置dialogfragment的进出动画 Window window=animateDialog.getDialog().getWindow(); window.setWindowAnimations(R.style.animate_dialog); 设置DialogFragment 的宽高: 在 onCreatView中设置是没有效果的,需要在onStart方法中设置,如下 public class AnimateDialog extends DialogFragment {@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //隐藏title getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE); //设置dialog的 进出 动画 getDialog().getWindow().setWindowAnimations(R.style.animate_dialog); /*写在这里没效果,要写在onStart里*/// getDialog().getWindow().getAttributes().width=getResources().getDisplayMetrics().widthPixels-200; View view=inflater.inflate(R.layout.layout_dialog, null); return view; } @Override public void onStart() { /*设置对话框的宽高*/ getDialog().getWindow().getAttributes().width=getResources().getDisplayMetrics().widthPixels-200; /*下面的方式设置也行*/// getDialog().getWindow().setLayout(getResources().getDisplayMetrics().widthPixels-200, getDialog().getWindow().getAttributes().height); super.onStart(); }}
|
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |