弹出框 ----有动画效果----在控件下方弹出

效果图
这里写图片描述

这是一个弹框有动态效果不过就是 东西多了一些 ,首先在res下创建anim文件夹,然后创建两个“set”的xml 文件: 这是样式引用的文件,让弹框—布局等拥有这个动画效果
res下多添加这一个文件,如图

这是其中一个的set xml 写法

这里写图片描述

在values 下的styles 这样就创建了一个样式了,是activity都可以用

这里写图片描述

弹框的布局 代码 : 这里面引用了三个的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">

    <RelativeLayout
        android:layout_width="70dp"
        android:layout_height="130dp"
        android:background="@drawable/yjb_ms_bottom_circular_red_background_for_view">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="1dp"
            android:layout_marginLeft="1dp"
            android:layout_marginRight="1dp"
            android:background="@drawable/yjb_ms_bottom_circular_white_background_for_view"
            android:orientation="vertical">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="10dp"
                android:background="#efefef"
                android:scaleType="fitXY"
                android:src="@drawable/yjb_ms_top_drawable" />

            <TextView
                android:id="@+id/tv_create_resume"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:drawableBottom="@drawable/yjb_ms_divider_for_horizontal"
                android:gravity="center"
                android:text="关闭"
                android:textColor="#000000"
                android:textSize="16dp" />

            <TextView
                android:id="@+id/tv_paste_resume"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:drawableBottom="@drawable/yjb_ms_divider_for_horizontal"
                android:gravity="center"
                android:text="关闭"
                android:textColor="#000000"
                android:textSize="16dp" />

            <!--<TextView-->
            <!--android:id="@+id/tv_guide_into_resume"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="0dp"-->
            <!--android:layout_weight="1"-->
            <!--android:gravity="center"-->
            <!--android:text="导入"-->
            <!--android:textColor="#000000"-->
            <!--android:textSize="16dp" />-->

        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

在mainActivity 中第一步当然初始化,还有一个获取屏幕的宽高为布局动画做基础 在 onCreate 中执行 getData() 方法先

这是onCreate 的内容

  private void getData() {
        button= (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showUserOperationMenu();
            }
        });

        //获取屏幕显示密度
        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        mDensity = metrics.density;
    }

二步

 /**
     * 显示用户操作弹窗
     */
    private void showUserOperationMenu() {

        //加载弹窗的布局XML文件
        View pwView = LayoutInflater.from(this).inflate(R.layout.yjb_ms_pw_menu_for_user_want_to_do, null);
        //初始化弹窗中的控件
        TextView tvCreatingResume = (TextView) pwView.findViewById(R.id.tv_create_resume);
        TextView tvPasteResume = (TextView) pwView.findViewById(R.id.tv_paste_resume);
//        TextView tvGuideIntoResume = (TextView) pwView.findViewById(R.id.tv_guide_into_resume);  
        // 创建弹窗,popupwindow中的listview能响应事件需将touchable和focusable均设为true才行!!!
        final PopupWindow pwForUserOperationMenu = new PopupWindow(pwView, ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT, true);

        //为各控件设置点击监听

        tvCreatingResume.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //      关闭弹框
                pwForUserOperationMenu.dismiss();
            }
        });


        tvPasteResume.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              //      关闭弹框
                pwForUserOperationMenu.dismiss();
            }
        });

        // 点击外部后,窗口消失
        pwForUserOperationMenu.setBackgroundDrawable(new BitmapDrawable(getResources(), BitmapFactory.decodeFile(null)));// 必不可少!!!
        pwForUserOperationMenu.setOutsideTouchable(true);

        //给弹窗设置动画
        pwForUserOperationMenu.setAnimationStyle(R.style.scale_y_animation_for_popupwindow);

        // 显示弹窗    屏幕密度乘以负数 往左偏移 反之向右
        pwForUserOperationMenu.showAsDropDown(button, (int) (10 * mDensity), 0);
    }

这就完了,简单吧弹出的布局自己想怎么写就这么写主要的还是创建showUserOperationMenu() 这方法中不会的了解一下,以后就会弹出宽了,样式网上很多,知道写法就行,还有就是样式也是分多种模式的

//

以后有啥功能想要的发邮件过来我会每周中选一个写出来
并且写到博客中.
55463869@qq.com或者15917398112@163.cm


这是Demo下载地址—-我的基本不超过一天的能写出来的都放一积分,半天写出来的不用积分—-这一个Demo我第一次写所以放了一积分

看完的同志点个顶我一下才有动力呀

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值