popwindow 位置和動畫

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>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章