// mWindow --> popupwindow layout --> 指定控件
private void showTopTipsPop(TipsPopWindow mWindow, View layout) {
View tipPop = mWindow.getContentView();
tipPop.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int popupWidth = tipPop.getMeasuredWidth();
int popupHeight = tipPop.getMeasuredHeight();
int[] location = new int[2];
layout.getLocationOnScreen(location);
// 此处算法,是在 指定view 的上方 展示
mWindow.showAtLocation(layout, Gravity.NO_GRAVITY,
(location[0] + layout.getWidth() / 2) - popupWidth / 2, location[1] - popupHeight);
//上下动画
TranslateAnimation translateAnimation = (TranslateAnimation) AnimationUtils.loadAnimation(PhotoActivity.this, R.anim.pop_translate);
tipPop.startAnimation(translateAnimation);
}
在 res 下创建 anim 文件夹
在该文件夹下创建
pop_translate 文件
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fillAfter="true"
android:fillBefore="false"
android:fromXDelta="0"
android:fromYDelta="0"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="-1"
android:repeatMode="reverse"
android:startOffset="10"
android:toXDelta="0"
android:toYDelta="-15%"/>