第一步 : 布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" > <LinearLayout
    android:id="@+id/menu_close"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_bg" //背景图片 9
android:gravity="center"
android:orientation="vertical" > <LinearLayout
android:id="@+id/menu_close_btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/menu_btn_bg" // 选择器
android:gravity="center"
android:orientation="vertical" > <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn_close" /> // 关闭的图标
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="退出"
android:textColor="#eee" />
</LinearLayout>
</LinearLayout> </LinearLayout>

第二步 点击 事件 调出 PopupWindow 的方法

    if (!menu_display) {    //如果没有显示
// 获取LayoutInflater实例
inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
// 这里的main布局是在inflate中加入的哦,以前都是直接this.setContentView()的吧?呵呵
// 该方法返回的是一个View的对象,是布局中的根
layout = inflater.inflate(R.layout.main_menu, null);
menuWindow = new PopupWindow(layout, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); // menuWindow.showAsDropDown(layout); //设置弹出效果
// menuWindow.showAsDropDown(null, 0, layout.getHeight());
menuWindow.showAtLocation(this.findViewById(R.id.mainweixin), // 整个布局的下面
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); // 设置layout在PopupWindow中显示的位置
// 如何获取我们main中的控件呢?也很简单
mClose = (LinearLayout) layout.findViewById(R.id.menu_close);
mCloseBtn = (LinearLayout) layout
.findViewById(R.id.menu_close_btn); // 下面对每一个Layout进行单击事件的注册吧。。。
// 比如单击某个MenuItem的时候,他的背景色改变
// 事先准备好一些背景图片或者颜色
mCloseBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// Toast.makeText(Main.this, "退出",
// Toast.LENGTH_LONG).show();
Intent intent = new Intent();
intent.setClass(MainWeixin.this, Exit.class);
startActivity(intent);
menuWindow.dismiss(); // 响应点击事件之后关闭Menu
}
});
menu_display = true;
} else { //显示了
// 如果当前已经为显示状态,则隐藏起来
menuWindow.dismiss();
menu_display = false;
}

PopupWindow --- 弹出底部窗体的更多相关文章

  1. DevExpress第三方控件使用实例之ASPxPopupControl弹出子窗体

    弹出页面控件:ASPxPopupControl, <dxpc:ASPxPopupControl ID="popubCtr" runat="server" ...

  2. Android popupwindow 弹出的位置问题

    在Android开发中,需要用到PopupWindow这个类.在初始化完成,显示之前,都需要获得这个对象的width,height去计算popupWindow弹出的位置. 这个时候会发现取得的widt ...

  3. 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法

    今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...

  4. MyEclipse弹出提示窗体

    MyEclipse弹出提示窗体 1.弹窗例如以下

  5. WPF 介绍一种在MVVM模式下弹出子窗体的方式

    主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...

  6. WPF的WebBrowser屏蔽弹出脚本错误窗体

    WPF自带的WebBrowser在訪问一些有问题的网页时常常跳出非常多提示脚本错误的窗体, 可是WPF没有自带屏蔽这些窗体的方法或属性. 所以网上找来一使用反射的方法来屏蔽弹出脚本错误窗体的方法, 非 ...

  7. WPF 在MVVM模式下弹出子窗体的方式

    主要是通过一个WindowManager管理类,在window后台代码中通过WindowManager注册需要弹出的窗体类型,在ViewModel通过WindowManager的Show方法,显示出来 ...

  8. 自定义PopupWindow弹出框(带有动画)

    使用PopupWindow来实现弹出框,并且带有动画效果 首先自定义PopupWindow public class LostPopupWindow extends PopupWindow { pub ...

  9. [Prism框架实用分享]如何在主程序中合理的弹出子窗体

    大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...

随机推荐

  1. 在 CentOS7最小化 下的编译安装:Nginx 1.5.2 + PHP 5.5.7 + MySQL 5.6.10

    1.安装Nginx: 安装包目录 mkdir -p /Data/tgzcd /Data/tgz 安装编译依赖 yum install wget yum install pcre yum install ...

  2. ubuntu14.04 pygame安装 python2.7

    系统:ubuntu14.04 LTS amd64python版本:2.7.6pygame版本:1.9.1release别这种方法了,这么安装不知道什么原因就出现了问题,在使用pygame.image. ...

  3. php关于<<<的用法

    Heredoc技术,在正规的PHP文档中和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术.但是现在的一些论坛程序,和部分文章系统,都巧妙的使用heredoc技术,来部分的实 ...

  4. zabbix实现mysql数据库的监控(三)

    上面一章“zabbix实现mysql数据库的监控(二)”使用MPM来监控mysql,但是遇到安装问题始终解决不了,这里改用percona-monitoring-plugins进行zabbxi上监控my ...

  5. dede调用二级下拉菜单方法

    <div id="menu">    <ul>  {dede:channelartlist typeid='top'  row='6' orderby='s ...

  6. C语言的操作符号

    #include <iostream> int main(void) { int a = 100, b = 40; //理解++在前还后的区别: a = b++; //a = b ; b= ...

  7. 使用 sqoop 将mysql数据导入到hive表(import)

    Sqoop将mysql数据导入到hive表中 先在mysql创建表 CREATE TABLE `sqoop_test` ( `id` ) DEFAULT NULL, `name` varchar() ...

  8. Java -- 键盘输入 Scanner, BufferedReader。 系统相关System,Runtime。随机数 Randrom。日期操作Calendar

    1. Scanner 一个基于正则表达式的文本扫描器,他有多个构造函数,可以从文件,输入流和字符串中解析出基本类型值和字符串值. public class Main { public static v ...

  9. BZOJ 1096 [ZJOI2007]仓库建设:斜率优化dp

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1096 题意: 有n个工厂,从左往右排成一排,分别编号1到n. 每个工厂里有p[i]件产品, ...

  10. node.js定时任务:node-schedule的使用

    安装 npm install node-schedule 使用方法 1:确定时间 例如:2014年2月14日,15:40执行 var schedule = require("node-sch ...