android中仿微信popwindow弹出方式
来源:互联网 发布:乐视电视怎么样 知乎 编辑:程序博客网 时间:2024/06/04 18:53
仿微信的底部弹出的相机选择方式,点击相机选择上面的按钮这个popwindow会自动消失,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/main"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/pop_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="vertical" >
<Button
android:id="@+id/btn_take_photo"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip"
android:text="拍照"
android:textStyle="bold" />
<Button
android:id="@+id/btn_pick_photo"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="5dip"
android:text="从相册选择"
android:textStyle="bold" />
<Button
android:id="@+id/btn_cancel"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginBottom="15dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="15dip"
android:text="取消"
android:textColor="#ffffff"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
下面实现代码
/********************************************************************************************************************************/
public class ChoosePicPopupWindow extends PopupWindow {
private Button btn_take_photo, btn_pick_photo, btn_cancel;
private View mMenuView;
public ChoosePicPopupWindow(Activity context,OnClickListener itemsOnClick) {
super(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mMenuView = inflater.inflate(R.layout.alert_dialog, null);
btn_take_photo = (Button) mMenuView.findViewById(R.id.btn_take_photo);
btn_pick_photo = (Button) mMenuView.findViewById(R.id.btn_pick_photo);
btn_cancel = (Button) mMenuView.findViewById(R.id.btn_cancel);
//取消按钮
btn_cancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//销毁弹出框
dismiss();
}
});
//设置按钮监听
btn_pick_photo.setOnClickListener(itemsOnClick);
btn_take_photo.setOnClickListener(itemsOnClick);
//设置SelectPicPopupWindow的View
this.setContentView(mMenuView);
//设置SelectPicPopupWindow弹出窗体的宽
this.setWidth(LayoutParams.FILL_PARENT);
//设置SelectPicPopupWindow弹出窗体的高
this.setHeight(LayoutParams.WRAP_CONTENT);
//设置SelectPicPopupWindow弹出窗体可点击
this.setFocusable(true);
//设置SelectPicPopupWindow弹出窗体动画效果
this.setAnimationStyle(R.style.AnimBottom);
//实例化一个ColorDrawable颜色为半透明
ColorDrawable dw = new ColorDrawable(0xb0000000);
//设置SelectPicPopupWindow弹出窗体的背景
this.setBackgroundDrawable(dw);
//mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
mMenuView.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
int height = mMenuView.findViewById(R.id.pop_layout).getTop();
int y=(int) event.getY();
if(event.getAction()==MotionEvent.ACTION_UP){
if(y<height){
dismiss();
}
}
return true;
}
});
}
}
- android中仿微信popwindow弹出方式
- Android PopWindow 弹出框
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- Android 创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单的两种方式
- 【Android】创建Popwindow弹出菜单
- Android点击菜单键(menu)弹出popWindow
- android 随手记 popwindow从下方弹出
- Android中popWindow弹出菜单的编写
- android popWindow 弹出时背景透明度渐变
- Android PopWindow弹出后,设置背景亮度
- Android——Popwindow从底部弹出
- 逛自己的微博,回顾曾经的那个“我”
- Qwt库的一个使用注意事项
- c++指针总结
- fastjson JSONArray 解析
- 《C#高级教程》学习笔记12
- android中仿微信popwindow弹出方式
- LayoutInflater的inflate函数用法详解
- 织梦文章页/列表页调用评论数、好评、差评的sql语句
- ArrayList和Vector的区别,HashMap和Hashtable的区别以及线程安全的理解
- C++_运算符重载
- android源码编译错误make ***[out/host/linux-x86/obj/EXECUTABL
- 复数
- Android 绘制文本垂直居中
- 关于js的冒泡事件,和一款基于jQuery的联动Select下拉框