LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.popupmenu,null);
//第一个参数表示窗体显示的内容,后边两个参数表示窗体的宽与高
PopupWindow m_popupWindow = new PopupWindow(view, 250, 350);
ListView m_btnOk = (ListView)findViewById(R.id.lv_id);
//第一个参数指定窗体现在在那个容器上,第二和第三参数分别表示距离此容器的x和y的距离
m_popupWindow.showAsDropDown(m_btnOk, 150,10);内容R.layout.popupmenu
要实现弹出框半透明:透明度是由LinearLayout的背景决定的 #00000000到#ff000000逐渐透明
<?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="#60000000"
android:orientation="vertical" >
<GridView android:layout_width="fill_parent"
android:id="@+id/gridView"
android:layout_height="wrap_content" android:numColumns="4"
android:background="#000000"
android:horizontalSpacing="10dp" android:verticalSpacing="10dp"
/>
</LinearLayout>
本文详细介绍了如何在Android中使用LayoutInflater、PopupWindow和自定义布局实现弹出框,并通过设置LinearLayout背景颜色来调整弹出框的透明度。包括布局文件XML的配置、关键代码解析及实例演示。
1万+

被折叠的 条评论
为什么被折叠?



