popupWind筛选

初始化

mPopupWindow=new PopupWindow(getContext());

pop显示

 private void showPop() {
   TextView tv_redu, tv_time, tv_rank, tv_share;
        mPopupWindow.setContentView(LayoutInflater.from(getContext()).inflate(R.layout.pop_add, null));
    // 为了避免部分机型不显示,我们需要重新设置一下宽高
        mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    // 设置pop透明效果
        mPopupWindow.setBackgroundDrawable(new ColorDrawable(0x0000));
    // 设置pop出入动画
        mPopupWindow.setAnimationStyle(R.style.pop_add);
    // 设置pop获取焦点,如果为false点击返回按钮会退出当前Activity,如果pop中有Editor的话,focusable必须要为true
        mPopupWindow.setFocusable(true);
    // 设置pop可点击,为false点击事件无效,默认为true
        mPopupWindow.setTouchable(true);
    // 设置点击pop外侧消失,默认为false;在focusable为true时点击外侧始终消失
        mPopupWindow.setOutsideTouchable(true);
    // 相对于 + 号正下面,同时可以设置偏移量
        mPopupWindow.showAsDropDown(txt_order, 0, 0);
    // 设置pop关闭监听,用于改变背景透明度
        mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            //toggleBright();
        }
    });

    tv_redu = mPopupWindow.getContentView().findViewById(R.id.tv_redu);
    tv_time = mPopupWindow.getContentView().findViewById(R.id.tv_time);
    tv_rank = mPopupWindow.getContentView().findViewById(R.id.tv_rank);
    tv_share = mPopupWindow.getContentView().findViewById(R.id.tv_share);

        tv_redu.setOnClickListener(this);
        tv_time.setOnClickListener(this);
        tv_rank.setOnClickListener(this);
        tv_share.setOnClickListener(this);
        }

打开关闭的样式

  <style name="pop_add">
        <item name="android:windowEnterAnimation">@anim/pop_add_show</item>
        <item name="android:windowExitAnimation">@anim/pop_add_hide</item>
    </style>

pop_add_show

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0"/>
    <scale
        android:duration="500"
        android:fromXScale="0.0"
        android:fromYScale="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:pivotX="85%"
        android:pivotY="0%"
        android:toXScale="1.0"
        android:toYScale="1.0"/>
</set>

pop_add_hide

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:toAlpha="0.0"/>
    <scale
        android:duration="500"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:pivotX="85%"
        android:pivotY="0%"
        android:toXScale="0"
        android:toYScale="0"/>
</set>

pop_add

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:gravity="center"
    >

    <TextView
        android:id="@+id/tv_redu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="热度排序"
        android:padding="5dp"
        />

    <TextView
        android:id="@+id/tv_time"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="时间排序" />

    <TextView
        android:id="@+id/tv_rank"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="等级排序" />

    <TextView
        android:id="@+id/tv_share"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp"
        android:text="分享排序" />

</LinearLayout>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值