PopupWindow底部弹出

说明:从屏幕底部弹出PopupWindow,有弹出隐藏动画效果.背景设置透明度.

效果图例如以下:


1.MainActivity.java   显示popwindow,宽高跟屏幕大小一样,设置一个透明度背景

public class MainActivity extends Activity {
	@Override
	public 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 parent = ((ViewGroup) this.findViewById(android.R.id.content)).getChildAt(0);
		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);
		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>

点击下载源代码

各位看官假设认为文章不错,帮忙点个赞吧。对于你来说是举手之劳,但对于我来说这就是坚持下去的动力。

假设你想第一时间看我们的后期文章。扫码关注公众号。每周不定期推送Android开发实战教程文章,你还等什么,赶快关注吧,学好技术,出任ceo。赢取白富美。

。。。

      Android开发666 - 安卓开发技术分享
            扫描二维码加关注

时间: 2024-12-28 14:39:38

PopupWindow底部弹出的相关文章

通用的popupwindow底部弹出框

前段时间做项目的时候,有几个底部弹出框,当时因为忙着赶进度所有就单独写了好几个popupwindow.后来就想着怎么实现一个通用的PopupWindow工具类 就是在要用到的时候创建该工具类的对象,并传入相应的框体布局,就可以实现了. 先看看效果,下面的两是调用同一个PopupWindowUtils创建的:       ok,先看看popupWindow的具体实现 import android.app.Activity; import android.graphics.drawable.Colo

【Android】android PopupWindow实现从底部弹出或滑出选择菜单或窗口

转载自:android PopupWindow实现从底部弹出或滑出选择菜单或窗口 Android PopupWindow的使用和分析 Popupwindow的使用 PopupWindow用法

Android-实现底部弹出PopupWindow并让背景逐渐变暗

Android-实现底部弹出PopupWindow并让背景逐渐变暗 在android开发中,经常需要通过点击某个按钮弹出对话框或者选择框,通过Dialog或者PopupMenu.PopupWindow都能实现. 这里主要介绍后两者:PopupMenu.PopupWindow的实现. 先看两个效果图左边PopupMenu,右边PopupWindow: Android-实现底部弹出PopupWindow并让背景逐渐变暗 一PopupMenu实现 二PopupWindow实现 一.PopupMenu实

Android 底部弹出提示框的解决办法(使用Activity以及PopupWindow)

本片文章主要谈探讨了如何实现在底部弹出提示框背景为半透明效果的实现.想要实现此种效果一般有两种方式一个是使用Activity设置Theme另一种方式就是使用PopupWindow设置样式实现效果. 一,使用Activity 首先是此activity的布局文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.andro

转 android 从底部弹出一个popuwindow,渐入渐出效果。我这里是用在购物车需要选择购买选项的操作。

最近要改客户端,需要实现一个从底部弹出的popuwindow,像我这种渣渣android技术,能整出popuwindow但是整不出动画,百度之,记录一下. 从下面这个地址转的 http://blog.csdn.net/yxhuang2008/article/details/42617805 最近因为要用到PopupWindow,所以,就在网上搜索了一下,发现挺多关于这样的文章,现在我把它们整理了一下. 1.Android PopupWindow 的使用技巧,http://www.cnblogs.

UIActionSheet底部弹出框

<底部弹出框来提示用户信息>    1.遵循代理方法<UIActionSheetDelete>    2.调用放法 [UIActionSheet *sheet=[UIActionSheet alloc]initWithTitle:@“通关了!” delegate:self cancelButtonTitle:@“取消” destructiveButtonTitle:@“购买” otherButtonTitles:@“购买1”,@“购买2”,nil]    [sheet showIn

拍照选择图片(Activity底部弹出)

效果图如下: 第一步 : 显示出的布局文件:alert_dialog.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_hei

Android编程:底部弹出的对话框

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN10 开发环境:Android Studio 2.2 Preview 3 说明: 两种方法实现底部弹出的对话框: Dialog DialogFragment 推荐用DialogFragment 效果图: 布局文件dialog_select_call.xml: <?xml version="1.0" encoding="utf-8"?> &l

用PopupWindow实现弹出菜单(弹出的菜单采用自定义布局)

     用PopupWindow实现弹出菜单是一个比较好的方式.当然我们还有一个类PopupMenu也能实现弹出菜单,但那个太过于局限了,所以不是很推荐. 这个实例的效果是这样的:点击按钮后,一个菜单从屏幕的右边滑入到屏幕中,点击按钮/空白处后菜单消失. 布局文件时一个按钮,我就不贴出代码了.下面是菜单的布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&