先看一下 translate 用法解析
http://developer.android.com/intl/zh-cn/guide/topics/resources/animation-resource.html
A vertical and/or horizontal motion. Supports the following attributes in any of the following three formats: values from -100 to 100 ending with "%", indicating a percentage relative to itself; values from -100 to 100 ending in "%p", indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value. Represents a TranslateAnimation
.
attributes:
-
Float or percentage. Starting X offset. Expressed either: in pixels relative to the normal position (such as
"5"
), in percentage relative to the element width (such as"5%"
), or in percentage relative to the parent width (such as"5%p"
).
android:fromXDelta
注意一句话:
Starting X offset......in pixels relative to the normal position
相对于 normal 位置。。。重点是怎么理解这个normal
直白点就是popup最后显示的位置。。。。。。以这个点做基准点进行offset(偏移)的设置
比如如上图片的popupwindow 如果想希望他从底部慢慢弹出。。
先确定基准点A 其他相对位置的计算都是以A作为参照点
水平向右为x方向 垂直向下为y方向
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromYDelta="100%"
android:toYDelta="0"/>
</set>
另外需要注意一下 popupWindow 动画的设置方法
/**
* <p>Change the animation style resource for this popup.</p>
*
* <p>If the popup is showing, calling this method will take effect only
* the next time the popup is shown or through a manual call to one of
* the {@link #update()} methods.</p>
*
* @param animationStyle animation style to use when the popup appears
* and disappears. Set to -1 for the default animation, 0 for no
* animation, or a resource identifier for an explicit animation.
*
* @see #update()
*/
public void setAnimationStyle(int animationStyle) {
mAnimationStyle = animationStyle;
}
这个需要定义在style.xml里 而不是直接饮用anim文件
<style name="popup_window_bottombar">
<item name="android:windowEnterAnimation">@anim/....</item>
<item name="android:windowExitAnimation">@anim/....</item>
</style>