测试代码:

package com.zzw.testpopuwindows;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.PopupWindow; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); final Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { LayoutInflater inflater = MainActivity.this.getLayoutInflater();
View view = inflater.inflate(R.layout.item, null); PopupWindow mPopupWindow = new PopupWindow(view, 500, 300); //设置背景的目的是使setOutsideTouchable方法生效
mPopupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher));
mPopupWindow.setOutsideTouchable(true);//在外点击消失
// mPopupWindow.showAsDropDown(button);
mPopupWindow.showAtLocation(MainActivity.this.getWindow().getDecorView(), Gravity.CENTER, 0, 0);
}
});
} }

item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:orientation="vertical" > <ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" /> <TextView
android:layout_gravity="center"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PopupWindow显示"
android:textColor="@android:color/holo_red_light" /> </LinearLayout>

PopupWindow的简单使用的更多相关文章

  1. PopupWindow的简单使用(结合RecyclerView)

    Android弹窗: 在Android中弹出式菜单(以下称弹窗)是使用十分广泛一种菜单呈现的方式,弹窗为用户交互提供了便利.关于弹窗的实现大致有以下两种方式AlertDialog和PopupWindo ...

  2. Android—PopupWindow的简单使用

    PopupWindow 是一个可以显示在当前 Activity 之上的浮动容器,这个Demo要实现的功能是,点击布局中的两个按钮,进而控制PopupWindow的显示与消失,代码中有详细的注释首先看一 ...

  3. Popupwindow 的简单实用,(显示在控件下方)

    第一步: private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML <?xml version="1.0" e ...

  4. 安卓学习笔记:使用PopupWindow创建简单菜单

    PopupWindow是一个弹出式窗口,它可以展示任意View.他会浮在当前窗口的上方展示. 下面看代码: public class MyActivity extends Activity { pri ...

  5. PopupWindow(2)简单示例-自定义弹出菜单

    本示例,用 popupWindow 自定义弹出菜单 public class CustomActionProvider extends ActionProvider implements OnMenu ...

  6. (转载) popupWindow 指定位置上的显示

    popupWindow 指定位置上的显示 标签: androidpopupWindowpopupWindow具体位置放置 2014-07-09 16:23 1114人阅读 评论(0) 收藏 举报  分 ...

  7. Android PopupWindow使用方法小结

    前几天要用到PopupWindow,一时竟想不起来怎么用,赶紧上网查了查,自己写了个demo,并在此记录一下PopupWindow的用法. 使用场景 PopupWindow,顾名思义,就是弹窗,在很多 ...

  8. 【转】Android新组件Material Dialog,SwipeRefreshLayout,ListPopupWindow,PopupMenu等

    朝花夕拾----新组件的学习和使用 分类: Android UI2015-06-26 11:31 440人阅读 评论(0) 收藏 举报 uidialogMaterial   目录(?)[-] Mate ...

  9. Android:PopupWindow简单弹窗改进版

    Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...

随机推荐

  1. 使用jaxp对比xml进行DOM解析

    /*DOM解析编程 •遍历所有节点 •查找某一个节点 •删除结点 •更新结点 •添加节点 /* package cn.itcast.jaxp; import java.io.File; import ...

  2. JAVA设计模式之依赖倒转原则

    3.1 依赖倒置原则的定义 依赖倒置原则(Dependence Inversion Principle,简称DIP)这个名字看着有点别扭,“依赖”还“倒置”,这到底是什么意思?依赖倒置原则的原始定义是 ...

  3. cocos2d-lua 3.5 android搭建常见错误

    新建一个项目,就不说了,就是用命令行 cocos new HelloLua -p com.wwj.hellolua -l lua -d ~/Cocos2dxProj ,生成下 然后把项目导入eclip ...

  4. C语言sizeof陷阱

    执行以下程序,查看输出: #include <stdio.h> #define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0])) int  ...

  5. C++历史(The History of C++)

    C++历史 早期C++ •1979: 首次实现引入类的C(C with Classes first implemented) 1.新特性:类.成员函数.继承类.独立编译.公共和私有访问控制.友元.函数 ...

  6. Android开发-API指南-进程与线程

    Processes and Threads 英文原文:http://developer.android.com/guide/components/processes-and-threads.html ...

  7. flash上传在spring mvc中出现的问题2

    转载请注明: TheViper http://www.cnblogs.com/TheViper  这两天本屌在做flash拼图上传遇到点坑 上传原理很简单,就是把上图右边画布区域BitmapData. ...

  8. bash中正则表达式

    工作中需要用bash的地方不是很多,之前只是大致了解过,每每用到都得去网上查询,遂决定以后将所用到的正则用法在这里统一收藏,便于学习. 1.echo 'inet addr:10.1.1.1  Bcas ...

  9. 学习总结 vs软件简单了解

    using System;using System.Collections.Generic;using System.Linq;using System.Text;//调用命名空间 using Sys ...

  10. 三味书屋 bbb

    为学日益 ,为道日损 .损之又损,以至于无为