怎么设置android中的popupwindow进入和退出的动画
2个回答
展开全部
首先定义显示效果的动画文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="120"
android:toYDelta="0"
android:duration="500" />
</set>
然后定义消失效果的动画文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="120"
android:duration="500" />
</set>
PopupWindow的动画显示效果是通过setAnimationStyle(int id)方法设置的,其中id为一个style的id,所以我们要在styles.xml文件中设置一个动画样式:
<style name="popwin_anim_style">
<item name="android:windowEnterAnimation">@anim/menushow</item>
<item name="android:windowExitAnimation">@anim/menuhide</item>
</style>
然后在程序中为PopupWindow设置就成:
PopupWindow pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
pop.setAnimationStyle(R.style.popwin_anim_style);
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="120"
android:toYDelta="0"
android:duration="500" />
</set>
然后定义消失效果的动画文件:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="0"
android:fromYDelta="0"
android:toYDelta="120"
android:duration="500" />
</set>
PopupWindow的动画显示效果是通过setAnimationStyle(int id)方法设置的,其中id为一个style的id,所以我们要在styles.xml文件中设置一个动画样式:
<style name="popwin_anim_style">
<item name="android:windowEnterAnimation">@anim/menushow</item>
<item name="android:windowExitAnimation">@anim/menuhide</item>
</style>
然后在程序中为PopupWindow设置就成:
PopupWindow pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
pop.setAnimationStyle(R.style.popwin_anim_style);
展开全部
设置popupWindow.setAnimationStyle(R.style.AnimationRightFade);
<style name="AnimationRightFade">
<item name="android:windowEnterAnimation">@anim/in_righttoleft</item>
<item name="android:windowExitAnimation">@anim/out_lefttoright</item>
</style>
//in_righttoleft:页面
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="500"/>
</set>
//out_lefttoright:页面
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="500"/>
</set>
<style name="AnimationRightFade">
<item name="android:windowEnterAnimation">@anim/in_righttoleft</item>
<item name="android:windowExitAnimation">@anim/out_lefttoright</item>
</style>
//in_righttoleft:页面
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%"
android:toXDelta="0"
android:duration="500"/>
</set>
//out_lefttoright:页面
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="100%"
android:duration="500"/>
</set>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询