现在的位置: 首页 > 综合 > 正文

PopupWindow学习

2013年07月24日 ⁄ 综合 ⁄ 共 862字 ⁄ 字号 评论关闭

PopupWindow在制作菜单时,经常用。问题在于控制该窗口的位置。

showAtLocation()第一个参数不知道啥意思,注意第二个参数:第二个参数跟第三、四个参数相关,用于定位

如下代码: Gravity.BOTTOM, 0, h,表示从最左下角,开始画。

 

pw = new PopupWindow(view,LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

int h = tv.getHeight();

//NND, 第一个参数, 必须找个View

pw.showAtLocation(findViewById(R.id.tv), Gravity.BOTTOM, 0, h);

 

设置整个窗体的背景,文件名:menu_bg_frame:

<?xml version="1.0" encoding="UTF-8"?>

<shape android:shape="rectangle"

  xmlns:android="http://schemas.android.com/apk/res/android">

    <solid android:color="#b4000000" />

    <stroke android:width="2.0dip" android:color="#b4ffffff" android:dashWidth="3.0dip" android:dashGap="0.0dip" />

    <padding android:left="7.0dip" android:top="7.0dip" android:right="7.0dip" android:bottom="7.0dip" />

    <corners android:radius="8.0dip" />

</shape>

 

使用方法:android:background="@drawable/menu_bg_frame"

 

就是这么简单。

 

参考地址:http://www.eoeandroid.com/thread-71824-1-1.html

 

 

抱歉!评论已关闭.