2017-08-29 84 views
0

我想点击一个按钮,一个按钮就会变成对话框,就像图片一样。我不知道如何做到这一点。 picture带动画的对话框

+0

从这里开始:https://developer.android.com/training/transitions/overview.html –

回答

0

我用下面的动画来实现类似的东西.. slide_up.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fillAfter="true"> 

    <scale xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="600" 
     android:fromXScale="0.6" 
     android:fromYScale="0.5" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="1.0" 
     android:toYScale="1.0" /> 

    <translate 
     android:duration="600" 
     android:fromYDelta="22%" 
     android:toYDelta="0%" /> 

    <alpha xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="600" 
     android:fillAfter="true" 
     android:fromAlpha="0.0" 
     android:toAlpha="1.0" /> 

</set> 

slide_down.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android" 
    android:fillAfter="true"> 
    <scale xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="600" 
     android:fromXScale="1.0" 
     android:fromYScale="1.0" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:toXScale="0.6" 
     android:toYScale="0.5" /> 

    <translate 
     android:duration="600" 
     android:fromYDelta="0%" 
     android:toYDelta="26%" /> 

    <alpha xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="600" 
     android:fillAfter="true" 
     android:fromAlpha="1.0" 
     android:toAlpha="0" /> 
</set> 

您可以根据您的需要改变pivotX和pivotY。 style.xml

<style name="DialogTheme" parent="Theme.AppCompat.Light.NoActionBar"> 
     <item name="android:background">@color/transparent</item> 
     <item name="android:windowEnterAnimation">@anim/slide_up</item> 
     <item name="android:windowExitAnimation">@anim/slide_down</item> 
</style> 

在对话框写

dialog.getWindow().getAttributes().windowAnimations = R.style.DialogTheme; 

希望这有助于!