---
title: "在一个按钮正下方显示一个popwindow"
author: "liangoogle"
date: "2012-11-06T23:48:02Z"
tags: []
categories: ["移动开发"]
slug: "popwindow"
draft: false
lastmod: "2012-11-06T23:48:02Z"
id: 1717860
url: "https://liangoogle.iteye.com/blog/1717860"
---

//这是show一个PopupWindow 

  PopupWindow mPopupWindow;

    public void showPopupWindow() {

LayoutInflater mLayoutInflater = (LayoutInflater) this.getSystemService(LAYOUT\_INFLATER\_SERVICE);

View music\_popunwindwow = mLayoutInflater.inflate(R.layout.portal\_select\_layout, null);

ListView portal\_select\_listView = (ListView) music\_popunwindwow.findViewById(R.id.portal\_select\_listView);

ArrayList androi = new ArrayList();

for (int i = 0; i &lt; 10; i++) {

androi.add(""+i);}

portal\_select\_listView.setAdapter( new ArrayAdapter(this,android.R.layout.simple\_spinner\_dropdown\_item,androi));

//popwindow的宽度和按钮的宽度相同都是230

mPopupWindow = new PopupWindow(music\_popunwindwow,230, LayoutParams.WRAP\_CONTENT);

mPopupWindow.setFocusable(true);

mPopupWindow.setOutsideTouchable(true);

mPopupWindow.update();

//位置在R.id.button的正下方

mPopupWindow.showAsDropDown(findViewById(R.id.button), 0,5);

}