DialogFragment 设置进出动画和宽高

</pre>在onCreatView中 直接设置 getDialog().getWindow().setWindowAnimations(R.style.animate_dialog);<p></p><p></p><pre code_snippet_id="561426" snippet_file_name="blog_20141224_2_9769632" name="code" class="java">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;
	}
	
}


    <style name="animate_dialog">
        
        <item name="android:windowEnterAnimation">@anim/dialog_enter</item>  
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DialogFragment进出动画可以通过在DialogFragment的onCreateDialog方法中设置Dialog的Window动画来实现。具体步骤如下: 1. 在DialogFragment中重写onCreateDialog方法,并创建一个AlertDialog或其他类型的Dialog对象。 ```java @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // 设置对话框的内容、标题等 // 获取Dialog对象 Dialog dialog = builder.create(); // 设置进出动画 dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; return dialog; } ``` 2. 在res目录下创建anim文件夹,并在其中定义进出动画的xml文件。例如,创建dialog_enter.xml和dialog_exit.xml。 ```xml <!-- dialog_enter.xml --> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="0.0" android:fromYScale="0.0" android:toXScale="1.0" android:toYScale="1.0" android:duration="300" /> </set> <!-- dialog_exit.xml --> <set xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:fromXScale="1.0" android:fromYScale="1.0" android:toXScale="0.0" android:toYScale="0.0" android:duration="300" /> </set> ``` 3. 在styles.xml文件中定义Dialog进出动画样式。 ```xml <style name="DialogAnimation"> <item name="android:windowEnterAnimation">@anim/dialog_enter</item> <item name="android:windowExitAnimation">@anim/dialog_exit</item> </style> ``` 4. 在DialogFragment所在的Activity中使用DialogFragment的show方法显示对话框。 ```java MyDialogFragment dialogFragment = new MyDialogFragment(); dialogFragment.show(getSupportFragmentManager(), "dialog"); ``` 这样就可以实现DialogFragment进出动画了。你可以根据自己的需求在anim文件夹中定义不同的动画效果,并在DialogFragment的onCreateDialog方法中设置不同的动画样式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值