PopupWindow 弹出在控件上
来源:互联网 发布:linux多线程并发编程 编辑:程序博客网 时间:2024/05/24 07:43
popupWindow的布局文件popup.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_parent" android:layout_height="wrap_content" android:background="#206d95e5" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="popupWindow" android:textSize="16sp" /> <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="button" android:textSize="16sp" /></LinearLayout>
Activity中弹出PopupWindow
public void showPopupWindow(View v){ View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.popup, null); Button button = (Button) contentView.findViewById(R.id.btn); final PopupWindow popupWindow = new PopupWindow(contentView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true); popupWindow.setTouchable(true); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainActivity.this, "onclick==action", Toast.LENGTH_SHORT).show(); } }); //检测屏幕消失的事件 popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { Log.d("Chunna.zheng","popupwindow消失啦!"); } }); // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框 popupWindow.setBackgroundDrawable(getResources().getDrawable( R.mipmap.ic_launcher)); //获取自身的长宽高 contentView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); int popupHeight = contentView.getMeasuredHeight(); int popupWidth = contentView.getMeasuredWidth(); //获取控件在屏幕上的位置,并赋值给location数组 int[] location = new int[2]; v.getLocationOnScreen(location); //在控件上方显示 popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, (location[0]), location[1] - popupHeight/2); // 如果要在控件下方显示,则使用这个方法 //popupWindow.showAsDropDown(v); }
阅读全文
0 0
- PopupWindow 弹出在控件上
- PopupWindow从上弹出
- Android popupwindow在指定控件正下方滑动弹出效果
- 在PopupWindow中再弹出PopupWindow问题
- android PopupWindow在控件的各个方向上的显示
- android popupwindow 弹出窗口在控件上方居中,比控件大一倍
- Android控件之PopupWindow弹出窗口
- PopupWindow上弹出另一个PopupWindow报异常解决办法
- 百度地图开发-将多个地点标记在地图上,点击节点弹出PopupWindow
- PopupWindow在android6.0无法弹出问题
- PopupWindow之在指定位置弹出小结
- popupwindow在activity上显示
- VC中实现在指定控件上弹出右键菜单
- popupWindow弹出
- 一个支持ListView的底部弹出控件 PopupWindow 小例子
- Android PopupWindow的使用技巧 Android上自定义弹出窗口
- PopupWindow显示在某个控件上方
- PopupWindow显示在某个控件上方
- Tensorflow实战Google深度学习框架 笔记
- 世界是平的-信息交换趋向于无障碍发展带来的影响(全球化)
- spring boot入门实例
- Esper的监听器收到两次同样的消息
- 实习日志(第四周)
- PopupWindow 弹出在控件上
- 2017.09.28 MQTT部分总结
- 解决Python unknown encoding:cp0
- android消息机制1-整体概览
- MutilcastSocket/DatagramPacket/DatagramSocket等
- three.js布尔运算源代码
- ubuntu14.04 samba配置
- 微信公众号—公众号支付JSPAI统一下单接口,详细流程
- 提高代码质量的技巧