zoukankan      html  css  js  c++  java
  • Animate a custom Dialog,自定义Dialog动画

    Inside res/style.xml
    
    <style name="AppTheme" parent="android:Theme.Light" />
    <style name="PauseDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
    </style>
    
    <style name="PauseDialogAnimation">
        <item name="android:windowEnterAnimation">@anim/fadein</item>
        <item name="android:windowExitAnimation">@anim/fadeout</item>
    </style>
    Inside anim/fadein.xml
    
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />

    Inside anim/fadeut.xml <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/anticipate_interpolator" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" /> MainActivity Dialog imageDiaglog= new Dialog(MainActivity.this,R.style.PauseDialog);

    http://stackoverflow.com/questions/4817014/animate-a-custom-dialog

    
    
    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <style name="PauseDialog" parent="@android:style/Theme.Dialog">
            <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
        </style>
    
        <style name="PauseDialogAnimation">
            <item name="android:windowEnterAnimation">@anim/spin_in</item>
            <item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
        </style>
    </resources>
    
    
    
    
    The windowEnterAnimation is one of my animations and is located in resanim. The windowExitAnimation is one of the animations that is part of the Android SDK.
    
    Then when I create the Dialog in my activities onCreateDialog(int id) method I do the following.
    
    Dialog dialog = new Dialog(this, R.style.PauseDialog);
    
    // Setting the title and layout for the dialog
    dialog.setTitle(R.string.pause_menu_label);
    dialog.setContentView(R.layout.pause_menu);
    Alternatively you could set the animations the following way instead of using the Dialog constructor that takes a theme.
    
    Dialog dialog = new Dialog(this);
    dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
  • 相关阅读:
    linux-centos7-vmware 虚拟机 设置静态 ip 地址,采用 nat 模式,实现连接公网
    mysql_5.7.20 二进制包 在Linux系统中的 安装和配置
    解决windows系统80端口被占用问题
    应用系统架构演变初探
    fastdfs-nginx扩展模块源码分析
    心已落定,入驻博客园
    mac iterm 提示符序列调整
    Background removal with deep learning
    git push fatal: The remote end hung up unexpectedly
    mac sed 使用踩坑实录
  • 原文地址:https://www.cnblogs.com/niray/p/4007846.html
Copyright © 2011-2022 走看看