PopupWindow底部弹出
来源:互联网 发布:战舰世界格拉斯数据 编辑:程序博客网 时间:2024/04/30 22:15
参考:http://m.blog.csdn.net/blog/lowprofile_coding/47785421#comment
说明:从屏幕底部弹出PopupWindow,有弹出隐藏动画效果.背景设置透明度.
效果如下:
1.MainActivity.java 显示popwindow,宽高跟屏幕大小一样,设置一个透明度背景
public class MainActivity extends Activity {@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViewById(R.id.button).setOnClickListener(new OnClickListener() {public void onClick(View v) {showPopwindow();}});}private void showPopwindow() {View popView = View.inflate(this, R.layout.camera_pop_menu, null);Button btnCamera = (Button) popView.findViewById(R.id.btn_camera_pop_camera);Button btnAlbum = (Button) popView.findViewById(R.id.btn_camera_pop_album);Button btnCancel = (Button) popView.findViewById(R.id.btn_camera_pop_cancel);int width = getResources().getDisplayMetrics().widthPixels;int height = getResources().getDisplayMetrics().heightPixels;final PopupWindow popWindow = new PopupWindow(popView,width,height);popWindow.setAnimationStyle(R.style.AnimBottom);popWindow.setFocusable(true);popWindow.setOutsideTouchable(false);// 设置允许在外点击消失OnClickListener listener = new OnClickListener() {public void onClick(View v) {switch (v.getId()) {case R.id.btn_camera_pop_camera:break;case R.id.btn_camera_pop_album:break;case R.id.btn_camera_pop_cancel:break;}popWindow.dismiss();}};btnCamera.setOnClickListener(listener);btnAlbum.setOnClickListener(listener);btnCancel.setOnClickListener(listener);ColorDrawable dw = new ColorDrawable(0x30000000);popWindow.setBackgroundDrawable(dw);
<pre name="code" class="java" style="border: 1px solid rgb(255, 255, 204); font-family: 'Courier New'; overflow: auto; font-size: 16px; line-height: 24px; background-color: rgb(255, 255, 252);"> View parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);popWindow.showAtLocation(parent, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);}}2.camera_pop_menu.xml Popupwindow加载的布局文件
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_margin="10dp" android:orientation="vertical" > <Button android:id="@+id/btn_camera_pop_camera" style="@style/txt_camera_pop_menu" android:layout_width="match_parent" android:layout_height="45dp" android:background="@drawable/pop_first_selector" android:text="@string/camera_pop_camera" android:textSize="18sp" /> <Button android:id="@+id/btn_camera_pop_album" style="@style/txt_camera_pop_menu" android:layout_width="match_parent" android:layout_height="45dp" android:background="@drawable/pop_last_selector" android:text="@string/camera_pop_album" android:textSize="18sp" /> <Button android:id="@+id/btn_camera_pop_cancel" style="@style/txt_camera_pop_menu" android:layout_width="match_parent" android:layout_height="45dp" android:layout_marginTop="10dp" android:background="@drawable/pop_single_selector" android:text="@string/camera_pop_cancel" android:textSize="18sp" /> </LinearLayout></RelativeLayout>代码下载地址:http://download.csdn.net/detail/lowprofile_coding/9025369
笔者注:①.这里的popupwindow要注意定位时的控件,即parent--是系统提供的。
②.这个popupwindow不能当下拉列表使用,目前只能只能通过点击下面的“取消”按钮或返回键使其消失
③.点击外部使Popupwindow消失方法:
设置popupwindow的背景为空,设置点击外面消失的代码 reportVideoPopwindow.setOutsideTouchable(true); reportVideoPopwindow.setFocusable(true); reportVideoPopwindow.setBackgroundDrawable(new BitmapDrawable());
0 0
- PopupWindow底部弹出
- PopupWindow底部弹出
- Popupwindow底部弹出
- PopupWindow底部弹出效果
- 底部弹出popUpWindow
- PopupWindow从底部弹出
- 从屏幕底部弹出PopupWindow
- popupwindow使用之底部弹出
- 从屏幕底部弹出PopupWindow
- popupwindow 底部弹出+背景半透明
- popupwindow仿侧滑菜单底部弹出
- 点击 PopupWindow ,ListView 底部弹出
- Android底部弹出的popupWindow
- 从底部弹出的PopupWindow
- PopupWindow实现屏幕底部弹出
- Android PopupWindow实战仿QQ底部弹出
- Android 之从底部弹出PopupWindow
- 自定义PopupWindow轻松实现从底部弹出
- 一次后门清除
- struts 表单数据只能获得一个参数,其他是null
- 微信分享导入库时注意事项
- Fragement
- js 基础
- PopupWindow底部弹出
- 【并行计算】使用MPI实现简单的并行素数筛法
- maven环境下的git ingore配置
- mmap函数,对于存入结构化数据的操作,以及映射内存的操作
- 老黎android笔记1
- 写在S5世界总决赛前夕
- 常用的Java设计模式(一)
- 讨厌的堆排序
- UIActionSheet