zoukankan      html  css  js  c++  java
  • Android中在activity中弹出一个popwindow

    //-----在onCreate方法--中------创建popwindow布局   --pop_item--------------------------
            View view=LayoutInflater.from(this).inflate(R.layout.pop_item, null);
            //找到两个按钮控件   登录 和我的
            bt_pop_login = (Button) view.findViewById(R.id.bt_pop_login);
            bt_pop_wode = (Button) view.findViewById(R.id.bt_pop_wode);
            //创建popwindow的大小
            // pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);  
            //创建popwindow的大小
            pop = new PopupWindow(view, 120, 200);  
            
            // 需要设置一下此参数,点击外边可消失  
            pop.setBackgroundDrawable(new BitmapDrawable());  
            //设置点击窗口外边窗口消失  
            pop.setOutsideTouchable(true);  
            // 设置此参数获得焦点,否则无法点击  
            pop.setFocusable(true);
            //可以设置  登录 和我的   的监听
            bt_pop_login.setOnClickListener(this);
            bt_pop_wode.setOnClickListener(this);

    //-----------判断--popwindow是否展示----------------------------

    if(pop.isShowing()) {  
                        // 隐藏窗口,如果设置了点击窗口外小时即不需要此方式隐藏  
                        pop.dismiss();  
                    } else {  
                        // 显示窗口  
                        pop.showAsDropDown(v);  
                    }  
                    
                    int [] location=new int [2];
                    v.getLocationOnScreen(location);
                    
                    pop.showAtLocation(tv_wode, Gravity.NO_GRAVITY, location[0], location[1]-pop.getHeight());
                   // pop.showAtLocation(v, Gravity.TOP, 20, 20);

    //------------pop_item.xml  文件布局中-------------------------

    <Button  
            android:id="@+id/bt_pop_login"  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="登录" />    
        <Button  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="我的"
            android:id="@+id/bt_pop_wode" /> 

  • 相关阅读:
    软件补丁问题(网络流24题)
    飞行员配对方案问题(网络流24题)
    [NOIp普及组2011]瑞士轮
    如何在Linux上安装QQ
    [洛谷P2420] 让我们异或吧
    高斯消元
    [SCOI2014]方伯伯的OJ
    [USACO1.3]虫洞
    KMP算法讲解
    [洛谷P1382] 楼房
  • 原文地址:https://www.cnblogs.com/changyiqiang/p/5788269.html
Copyright © 2011-2022 走看看