popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
来源:互联网 发布:ip切换软件 编辑:程序博客网 时间:2024/03/29 23:45
popupwindow实现弹出菜单功能非常实用,在有布局中经常出现,给用户体验非常不错,以下是我总结popupwindow实现弹出窗口的经常使用范例:
1. 先看效果:
2. main.xml
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:background="@drawable/bg_5"> <ListView android:id="@+id/lv_id" android:layout_height="wrap_content" android:layout_width="match_parent" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_alignParentBottom="true" android:background="@drawable/title_weekend_bg"> <Button android:id="@+id/but_menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="菜单" android:background="@drawable/button_select"/> <Button android:id="@+id/but_news" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="新闻" android:background="@drawable/button_select" android:layout_marginLeft="10dp"/> </LinearLayout></RelativeLayout>
3. popupmenu.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="match_parent" android:layout_width="match_parent" android:background="@drawable/main" android:orientation="vertical"> <TextView android:id="@+id/open_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="打开"/> <TextView android:id="@+id/save_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="w保存"/> <TextView android:id="@+id/my_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我的留言"/> <TextView android:id="@+id/about_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="关于我们"/> <TextView android:id="@+id/help_id" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="帮助"/></LinearLayout>
4. 核心java代码:按下按钮时显示弹出窗口
menuBut.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { LayoutInflater layoutInflater = getLayoutInflater(); View view = layoutInflater.inflate(R.layout.popupmenu,null); //PopupWindow弹出的窗口显示的view,第二和第三参数:分别表示此弹出窗口的大小 m_popupWindow = new PopupWindow(view, 150, 250); //PopupWindow弹出的窗口显示的位置 ,第一个参数指在那个view上 ,第二和第三参数分别表示距离此view的x和y的距离 m_popupWindow.showAsDropDown(m_btnOk, 0,0); } });
5. 关闭弹出的窗口
public boolean onTouchEvent(MotionEvent event) { //关闭m_popupWindow窗口 m_popupWindow.dismiss(); return super.onTouchEvent(event); }
- popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
- PopupWindow实现弹出菜单效果
- [Android实例] popupwindow实现弹出菜单效果
- PopupWindow实现弹出窗口
- android中使用PopupWindow实现弹出窗口菜单
- Android PopupWindow弹出窗口的完美实现(实现弹出背景变暗效果)
- PopupWindow弹出后其他地方变暗的效果如何实现
- Javascript实现弹出菜单,弹出窗口
- Javascript实现弹出菜单,弹出窗口
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android之用PopupWindow实现弹出菜单
- Android用PopupWindow实现弹出菜单实例
- 前端:一款Web轮放器 - 支持文字、图片传送带式轮放
- Firefox 4中javascript脚本执行的变化
- AL32UTF8和UTF8字符集
- 手机产品设计之用户引导
- WIN7 home 如何开启administrator账户
- popupwindow 如何实现弹出菜单效果_popupwindow 实现弹出窗口范例
- iPhone 利用CG API画一个饼图(Pie chart) 百分比圆 以及 响应扇形点击事件
- 微软历史最高市值是多少?
- firefox常用快捷键集合
- linux下文件压缩与解压操作
- iPhone 短信音及显示名称更改方法
- Mule3配置文件
- 怎样设计一个合理的软件试用机制或类似机制?
- Delphi7 修改单元文件的名字