popwindow 位置和动画:
关于这个popwindow的位置, 和动画 搞了半天, 才搞明白。。。记录。
popwindow 位置
showPop() {
setWidth(w); //需要先设置尺寸
setHeight(h); //需要设置尺寸
showAtLocation(parentview,gravity, x, y );
//parentview : parentview
//gravity :popwindow 在 parentview中的位置
//x :popwindow在screen的x坐标位置 //注意是相当于屏幕的。
//y :popwindow在screen的y坐标位置。。//注意是相当于与屏幕的
}
动画:位移动画可以和渐变动画配合
<?xml version="1.0" encoding="utf-8"?>
<!-- 底部滑入动画 -->
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- fromYDelta toYDelta 可以是百分比, 也可以是像素 -->
<translate
android:duration="200"
android:fromYDelta="100%p"
android:toYDelta="0" />
<alpha
android:duration="200"
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
附带一个获取view location的方法。
<span style="font-size:10px;"> public static Rect locateView(View v) {
int[] loc_int = new int[2];
if (v == null)
return null;
try {
v.getLocationOnScreen(loc_int);
}
catch (NullPointerException npe) {
// Happens when the view doesn't exist on screen anymore.
return null;
}
Rect location = new Rect();
location.left = loc_int[0];
location.top = loc_int[1];
location.right = location.left + v.getWidth();
location.bottom = location.top + v.getHeight();
return location;
}</span>