PopupWindow实现弹窗效果
来源:互联网 发布:论文引用格式网络文章 编辑:程序博客网 时间:2024/06/01 16:09
PopWindow是一个弹出的窗口,它的效果就是在当前Activity上面再显示一层图层。这是它的继承关系:
java.lang.Object
↳ android.widget.PopupWindow
他的实现方式有多种,比如我们可以用PopupWindow(Context context) 和
PopupWindow() 实现。
本文主要描述的是类似效果的实现:
效果图
初始化方法:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); parentView = getLayoutInflater().inflate(R.layout.activity_basic_infor, null); setContentView(parentView); initPopWindow(); } public void initPopWindow() { pop = new PopupWindow(BasicInforActivity.this);//获得PopupWindow对象 View view = getLayoutInflater().inflate(R.layout.layout_popupwindows, null);//加载PopupWindow的布局 ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup); pop.setWidth(LayoutParams.MATCH_PARENT);//设置宽度高度 pop.setHeight(LayoutParams.WRAP_CONTENT); pop.setBackgroundDrawable(new BitmapDrawable()); pop.setFocusable(true);//设置是否获得焦点 pop.setOutsideTouchable(true);//设置当点击外部时的效果 pop.setContentView(view);//将布局加载到pop中 RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent);//获取界面中的各种控件 Button btnTakePhoto = (Button) view.findViewById(R.id.item_popupwindows_camera); Button btnAblum = (Button) view.findViewById(R.id.item_popupwindows_Photo); Button btnCancle = (Button) view.findViewById(R.id.item_popupwindows_cancel); parent.setOnClickListener(this);//Activity实现OnClickListner,设置监听。 btnTakePhoto.setOnClickListener(this); btnAblum.setOnClickListener(this); btnCancle.setOnClickListener(this); }
布局文件代码:
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/parent" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#99000000" > <LinearLayout android:id="@+id/ll_popup" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginLeft="15dp" android:layout_marginRight="15dp" android:orientation="vertical" > <Button android:id="@+id/item_popupwindows_camera" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:text="拍照" android:textSize="15sp" /> <View android:layout_width="match_parent" android:layout_height="0.5dp" android:background="#f3f3f3" /> <Button android:id="@+id/item_popupwindows_Photo" android:layout_width="match_parent" android:layout_height="50dp" android:background="#ffffff" android:text="从相册中选取" android:textSize="15sp" /> <Button android:id="@+id/item_popupwindows_cancel" android:layout_width="match_parent" android:layout_height="50dp" android:layout_marginBottom="15dp" android:layout_marginTop="15dp" android:background="#ffffff" android:text="取消" /> </LinearLayout></RelativeLayout>
最后就是显示PopupWindow和隐藏的代码:
pop.showAtLocation(parentView, Gravity.BOTTOM, 0, 0);//显示的代码 pop.dismiss();//消失的代码 ll_popup.clearAnimation();
1 0
- PopupWindow实现弹窗效果
- Android中PopupWindow实现弹窗输入的效果
- Android 自定义PopupWindow实现悬浮窗效果
- popupWindow 实现悬浮半透明效果
- PopupWindow实现弹出菜单效果
- 使用PopupWindow和Activity两种不同的方式实现弹窗效果
- Android实现PopupWindow 弹窗效果 可用于提示信息等
- Android实现PopupWindow 弹窗效果 可用于提示信息等
- popupWindow添加viewFlipper实现菜单动画效果
- Android PopupWindow介绍及实现菜单效果
- [Android实例] popupwindow实现弹出菜单效果
- Android PopupWindow介绍及实现菜单效果
- Android PopupWindow介绍及实现菜单效果
- 9宫格效果-gridview+popupWindow实现
- setAnimatjionStyle实现popupwindow的动画效果
- Android PopupWindow介绍及实现菜单效果
- PopupWindow实现dialog效果背景变色
- 自定义PopupWindow实现下拉菜单选项效果
- HDU 5416 CRB and Tree (2015多校第10场)
- 面试宝典_JVM
- luaplus和c++之间的代码交互
- 汇编语言的重要性
- adb logcat获取异常日志代码
- PopupWindow实现弹窗效果
- leetcode: Minimum Depth of Binary Tree
- Hibernate知识点
- UIButton设置圆角
- 解决 win32控制台程序一闪而过
- Swift学习笔记(十七)协议
- push和pushl的区别
- ios线程-GCD
- Nginx Proxy cache + Perl + ImageMagick 做Wap站图片适配 实时压缩