PopupWindow指定位置弹出
2016-04-18 16:39
351 查看
private PopupWindow mPopupWindow = null; public static boolean isPopBackPhone = false; // private int[] locationPhone = new int[2]; @SuppressWarnings("deprecation") @SuppressLint("InlinedApi") private void pop_wallet() { final View contentView; isPopBackPhone = false; if (mPopupWindow == null) { contentView = LayoutInflater.from(this).inflate(R.layout.pop_wallet_type, null); mPopupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); mPopupWindow.setBackgroundDrawable(new BitmapDrawable()); mPopupWindow.setTouchable(true); mPopupWindow.setOutsideTouchable(true); mPopupWindow.setFocusable(true);// 设置外部可点击 mPopupWindow.update(); contentView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mPopupWindow.isShowing()) { img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow)); mPopupWindow.dismiss(); } } }); final TextView txt_type0 = (TextView) contentView .findViewById(R.id.txt_type0); final TextView txt_type1 = (TextView) contentView .findViewById(R.id.txt_type1); final TextView txt_type2 = (TextView) contentView .findViewById(R.id.txt_type2); final View view_line0 = (View) contentView .findViewById(R.id.view_line0); final View view_line1 = (View) contentView .findViewById(R.id.view_line1); final View view_line2 = (View) contentView .findViewById(R.id.view_line2); txt_type0.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPopupWindow.dismiss(); } }); txt_type1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPopupWindow.dismiss(); } }); txt_type2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { bussinessType = "brokerageSettled"; mPopupWindow.dismiss(); } }); } mPopupWindow.setAnimationStyle(R.style.TypeSelAnimationFade); // findViewById(R.id.view_line_phone).getLocationInWindow(locationPhone); // mPopupWindowPhone.showAtLocation(getWindow().getDecorView(), // Gravity.NO_GRAVITY, locationPhone[0], locationPhone[1]); mPopupWindow.showAsDropDown(findViewById(R.id.view_line)); mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow)); mPopupWindow.dismiss(); } }); }
@Override public boolean onTouchEvent(MotionEvent event) { if (mPopupWindow != null && mPopupWindow.isShowing()) { img_arrow.setImageDrawable(mActivity.getResources().getDrawable(R.mipmap.flow)); mPopupWindow.dismiss(); mPopupWindow = null; } return super.onTouchEvent(event); }
背景灰色透明效果
backgroundAlpha(0.7f);
backgroundAlpha(1f);
/** * 设置添加屏幕的背景透明度 * * @param bgAlpha */ public void backgroundAlpha(float bgAlpha) { WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes(); mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); lp.alpha = bgAlpha; //0.0-1.0 mActivity.getWindow().setAttributes(lp); }
<style name="TypeSelAnimationFade"> <item name="android:windowEnterAnimation">@anim/typesel_push_top_in</item> <item name="android:windowExitAnimation">@anim/typesel_push_top_out</item> </style>
typesel_push_top_in---------:
<?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/linear_interpolator" > <scale android:duration="100" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="0.0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="0.0%" android:pivotY="0.0%" android:toXScale="1.0" android:toYScale="1.0" /> </set>
typesel_push_top_out---------:
<?xml version="1.0" encoding="UTF-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" > <alpha android:duration="@android:integer/config_shortAnimTime" android:fromAlpha="1.0" android:toAlpha="0.0" /> <scale android:duration="120" android:fillAfter="true" android:fromXScale="1.0" android:fromYScale="1.0" android:interpolator="@android:anim/linear_interpolator" android:pivotX="0.0%" android:pivotY="0.0%" android:toXScale="1.0" android:toYScale="0.0" /> </set>
相关文章推荐
- "围观"设计模式(6)--开闭原则(Open/Closed Principle)
- linux-常用命令
- Linux下从信号量看线程调度时间
- linux命令详解——sar
- linux命令详解——sar
- MVP框架 – Ted Mosby的软件架构
- nginx 301 域名重定向方法
- centos下安装php
- centos 6 启用ftp功能
- Hadoop 知识库
- 关于adb logcat
- DenyHosts 防止SSH爆破
- linux打包压缩命令
- Linux隐藏多个进程
- shell下的进程
- OpenGL纹理使用
- centos 安装MySQL
- Apache与Tomcat联系及区别
- 在工程里寻找各种对象(如:右键菜单pop1,在menus里面寻找)
- 【转】Linux设备驱动--块设备(一)之概念和框架