Android PopupWindow使用
来源:互联网 发布:pyqt4 linux 编辑:程序博客网 时间:2024/05/07 09:32
//代码
package com.mark.pop.win;import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.MotionEvent;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.PopupWindow;import android.widget.RelativeLayout;public class PopupWindowDemoActivity extends Activity{private Button pop_windowButton;private PopupWindow menuPop=null;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);pop_windowButton=(Button) findViewById(R.id.pop_window);pop_windowButton.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v){View paopaoView = getLayoutInflater().inflate(R.layout.pop_menu, null);//这里最关键,不在pop的View的里面找到相映的ID,还真不好关闭popWinButton pop_play_btn=(Button) paopaoView.findViewById(R.id.play_btn);menuPop = new PopupWindow(paopaoView, RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);menuPop.showAtLocation(pop_windowButton, Gravity.LEFT,0,-120);pop_play_btn.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v){closePop();}});}});}@Overridepublic boolean onTouchEvent(MotionEvent event){closePop();return super.onTouchEvent(event);}private void closePop(){if(null!=menuPop){menuPop.dismiss();}}}
//pop_menu.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/menu_btns" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/play_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_menu_pause" /><!--这个依旧是布局--> <Button android:id="@+id/sound_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_menu_sound" /><!--布局--> <Button android:id="@+id/help_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_menu_help" /><!--布局--> <Button android:id="@+id/about_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_menu_about" /><!--布局--> <Button android:id="@+id/home_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_menu_home" /><!--布局--></LinearLayout>
//button_menu_pause.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false"android:drawable="@drawable/pause_menu_1" /><!--未按下时--><item android:state_pressed="true"android:drawable="@drawable/pause_menu_2" /><!--已按下时--><item android:state_focused="true"android:drawable="@drawable/pause_menu_2" /><!--已点击时--><item android:drawable="@drawable/pause_menu_1" /><!--这个就是图片了 default--></selector>
//button_menu_sound.xml
同上
//button_menu_help.xml
同上
//button_menu_about.xml
同上
- Android PopupWindow的使用
- Android PopupWindow的使用
- Android PopupWindow的使用!!!
- Android PopupWindow使用
- 【Android】 PopupWindow使用小结
- Android PopupWindow的使用!!!
- android PopupWindow 使用
- Android PopupWindow简单使用
- Android PopupWindow 的使用
- Android PopupWindow的使用
- android PopupWindow的使用
- Android PopupWindow使用详解
- Android PopupWindow的使用
- Android PopupWindow 的使用
- Android PopupWindow的使用
- Android PopupWindow简单使用
- Android PopupWindow的使用
- Android PopupWindow的使用
- 抽象工厂重点模块设计
- module学习(6)
- 手机与笔记本共享上网 图文教程
- sql优化学习
- Windows文件系统以及文件粉碎原理
- Android PopupWindow使用
- sql server 2005学习记录-个人学习
- Google Protocol Buffer 的使用和原理
- 泛型的入门学习及思考
- UIPickerView
- css纵向商城分类导航菜单
- 字符数组和字符指针的区别
- 背部肌群锻炼方法大全
- 汇编基础学习和一些基本总结