自定义popwindow,从底部弹出和消失动画

1.使用方法

popWindow = new CustomPopWindow(this, new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        }
                    }
                });
                popWindow.showAtLocation(this.findViewById(R.id.etActivityEditFeedBack),Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置

2.自定义popwindow

public class CustomPopWindow extends PopupWindow implements View.OnClickListener {

    private TextView OK;
    private TextView GiveUp;
    private TextView Cancel;
    private View mMenuView;

    public CustomPopWindow(Activity context, View.OnClickListener itemsOnClick) {
        super(context);
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mMenuView = inflater.inflate(R.layout.custom_popwindow, null);
        mMenuView.setOnClickListener(this);
        OK = (TextView) mMenuView.findViewById(R.id.tvPopwindowOK);
        GiveUp = (TextView) mMenuView.findViewById(R.id.tvPopwindowGiveUp);
        Cancel = (TextView) mMenuView.findViewById(R.id.tvPopwindowCancel);
        Cancel.setOnClickListener(this);
        OK.setOnClickListener(itemsOnClick);
        GiveUp.setOnClickListener(itemsOnClick);

        //设置SelectPicPopupWindowView
        setContentView(mMenuView);
        //设置SelectPicPopupWindow弹出窗体的宽
        setWidth(LinearLayout.LayoutParams.MATCH_PARENT);
//        //设置SelectPicPopupWindow弹出窗体的高
        setHeight(LinearLayout.LayoutParams.MATCH_PARENT);
        ColorDrawable dw = new ColorDrawable(0x00000000);
        setBackgroundDrawable(dw);
        setFocusable(true);
        setAnimationStyle(R.style.popwindow_anim_style);
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }
}

3.在style中设置动画样式

  <!--  Popwindow样式 -->
    <style name="popwindow_anim_style">
        <item name="android:windowEnterAnimation">@anim/popwindow_show_anim</item>
        <item name="android:windowExitAnimation">@anim/popwindow_hidden_anim</item>
    </style>

4.popwindow布局custom_popwindow.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#90000000"
    android:gravity="bottom|center_horizontal"
    android:orientation="vertical">


    <TextView
        android:id="@+id/tvPopwindowOK"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_titlebar"
        android:gravity="center"
        android:padding="@dimen/padding_10"
        android:text="完成编辑"
        android:textSize="@dimen/text_size_18" />

    <TextView
        android:id="@+id/tvPopwindowGiveUp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/background_titlebar"
        android:gravity="center"
        android:padding="@dimen/padding_10"
        android:text="放弃编辑"
        android:textColor="@color/color_red"
        android:textSize="@dimen/text_size_18" />


    <TextView
        android:id="@+id/tvPopwindowCancel"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/padding_10"
        android:layout_marginTop="@dimen/padding_10"
        android:background="@drawable/background_titlebar"
        android:gravity="center"
        android:padding="10dp"
        android:text="取消"
        android:textSize="@dimen/text_size_18" />
</LinearLayout>

5.anim 动画样式

popwindow_show_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="1000"
        android:fromYDelta="100%p"
        android:toYDelta="0" />
</set>

popwindow_hidden_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="1000"
        android:fromYDelta="0"
        android:toYDelta="100%p" />
</set>

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值