Android popupwindow在指定控件正下方滑动弹出效果

1.PopupWindow的布局(record_popupwindow.xml)

<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="@color/transparent_black">        <ImageView            android:id="@+id/iv_cancel"            android:layout_width="@dimen/dp_33"            android:layout_height="@dimen/dp_33"            android:background="@mipmap/img_cancel"            android:layout_alignParentRight="true"            android:layout_marginTop="@dimen/dp_95"            android:layout_marginRight="@dimen/dp_47"            />        <RelativeLayout            android:id="@+id/rl_popupwindow"            android:layout_width="@dimen/dp_282"            android:layout_height="@dimen/dp_349"            android:layout_centerInParent="true"            android:background="@color/colorPrimary">            <ImageView                android:id="@+id/iv_recommend"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:background="@mipmap/recommend_text"                android:layout_centerHorizontal="true"                android:layout_marginTop="@dimen/dp_100"                />            <android.support.v7.widget.RecyclerView                android:id="@+id/rv_record_recommend"                android:layout_width="match_parent"                android:layout_height="match_parent"                android:layout_below="@+id/iv_recommend"                android:layout_marginTop="@dimen/dp_15"                >            android.support.v7.widget.RecyclerView>        RelativeLayout>        <ImageView            android:id="@+id/iv_record_recommend_offline"            android:layout_width="@dimen/dp_110"            android:layout_height="@dimen/dp_125"            android:layout_centerHorizontal="true"            android:layout_marginTop="@dimen/dp_95"            android:background="@mipmap/offline_logo"/>        <Button            android:layout_width="@dimen/dp_168"            android:layout_height="@dimen/dp_32"            android:layout_below="@+id/rl_record_popupwindow"            android:background="@drawable/bg_pic_saved"            android:layout_centerHorizontal="true"            android:text="查看产品"            android:textColor="@color/white"            android:textSize="@dimen/dp_15"            android:layout_marginTop="@dimen/dp_20"            />RelativeLayout>

2.BaseApplication.class

public class BaseApplication extends Application {//static代码可以防止内存泄漏static Context mContext;    static Handler sHandler;@Override    public void onCreate() {        super.onCreate();        mContext = getApplicationContext();        sHandler = new Handler();}public static Context getContext() {        return mContext;    }    public static Handler getHandler() {        return sHandler;    }}

3.通过子线程更新PopupWindow

 BaseApplication.getHandler().postDelayed(new Runnable() {            @Override            public void run() {                showPopupWindow();            }        },2000);

4.PopupWindow在Activity中显示

public void showPopupWindow(){        PopupWindow popupWindow = new PopupWindow(this);        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);        popupWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);        popupWindow.setContentView(LayoutInflater.from(this).inflate(R.layout.record_popupwindow, null));        popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));        popupWindow.setOutsideTouchable(false);        popupWindow.setFocusable(true);        popupWindow.setClippingEnabled(false);        popupWindow.showAtLocation(LoanManagerActivity.this.mLayout, Gravity.CENTER,0,0);    }
popupwindow 的动画效果

PopupWindow弹出动画设置

1.anim_popupwindow_in.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:interpolator="@android:anim/overshoot_interpolator"    android:duration="1000"    >    <scale        android:fromXScale="0.0"        android:fromYScale="0.0"        android:pivotX="50%"        android:pivotY="50%"        android:toXScale="1.0"        android:toYScale="1.0"        />set>

2.anim_popwindow_out.xml

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"    android:duration="500">    <scale        android:fromXScale="1.0"        android:fromYScale="1.0"        android:pivotX="50%"        android:pivotY="50%"        android:toXScale="0.0"        android:toYScale="0.0" />set>

duration:即动画执行时长
scale:缩放动画
fromXScale:横向开始比例
fromYScale:纵向开始比例
pivotX:缩放的参照物横轴 一般为50%,即是横向的中间点
pivotY:缩放的参照物纵轴 一半为50%,即是纵向的中间点
toXScale:动画结束时横向的比例 float值 1即是保持正常大小
toYScale:动画结束时纵向的比例

2.定义动画style
<style name="pop_animation" parent="android:Animation">    "android:windowEnterAnimation">@anim/anim_popwindow_in    "android:windowExitAnimation">@anim/anim_popupwindow_outstyle>

更多相关文章

  1. ViewPager
  2. Android(安卓)动画1--View控件的显示和隐藏效果
  3. 一个不错的启动菜单显示屏动画效果
  4. android 动画学习系列(一)
  5. 最受欢迎的文章汇总
  6. 介绍两个Android开源项目:Android显示GIF动画
  7. android 动画分类
  8. Android(安卓)调用相册 拍照 实现系统控件缩放 切割图片
  9. android viewpage的使用

随机推荐

  1. Android(安卓)IPC机制之 Android的各种IP
  2. Vue.js实战——开发Android(安卓)Hybird
  3. 编译 go 源码为 android 动态库(so)
  4. Android(安卓)手机上安装并运行 Ubuntu 1
  5. Android(安卓)自定义控件外观
  6. Android(安卓)Spinner与适配器模式详解及
  7. Android温故之-BroadcastReceiver
  8. android实现横向滚动
  9. Android(安卓)的木马危机
  10. Android新手入门2016(2)--Mac下的Android开