android PopupWindow使用实例_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > android PopupWindow使用实例

android PopupWindow使用实例

 2015/3/13 21:03:06  jenson138  程序员俱乐部  我要评论(0)
  • 摘要:.java1privatePopupWindowmMenu;234publicvoidCreatMenu(Viewview){5if(mMenu==null){6LayoutInflaterinflater=(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);7Viewv=inflater.inflate(R.layout.popuppindow_group,8null,false)
  • 标签:android 使用 实例

.java

 1 private PopupWindow mMenu;
 2 
 3 
 4     public void CreatMenu(View view) {
 5         if (mMenu == null) {
 6             LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 7             View v = inflater.inflate(R.layout.popuppindow_group,
 8                     null, false);
 9             LinearLayout lytRequest = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_request);
10             lytRequest.setOnClickListener(this);
11             LinearLayout lytExit = (LinearLayout) v.findViewById(R.id.lyt_pw_groupmember_exit);
12             lytExit.setOnClickListener(this);
13             mMenu = new PopupWindow(v);
14 //            moreMenu.setWidth(300);
15             mMenu.setWidth(LayoutParams.WRAP_CONTENT);
16             mMenu.setHeight(LayoutParams.WRAP_CONTENT);
17             mMenu.showAsDropDown(view);
18         } else {
19             if (mMenu.isShowing()) {
20                 mMenu.dismiss();
21             } else {
22                 mMenu.showAsDropDown(view);
23             }
24         }
25     }    
26 
27 @Override
28     public void onClick(View v) {
29         // TODO Auto-generated method stub
30         switch (v.getId()) {
31          case R.id.lyt_activitygroupmembers_menu:
32              CreatMenu(v);
33          break;
34          case R.id.lyt_pw_groupmember_request:
35              Toast.makeText(this, "request", Toast.LENGTH_SHORT).show();
36              mMenu.dismiss();
37          break;
38          case R.id.lyt_pw_groupmember_exit:
39              Toast.makeText(this, "exit", Toast.LENGTH_SHORT).show();
40              mMenu.dismiss();
41          break;         
42          
43         }
44 
45     }

 

.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/darker_gray" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:id="@+id/lyt_pw_groupmember_request"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/TextView03"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:gravity="left|center"
                android:text="request"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/TextView04"
                android:layout_width="match_parent"
                android:layout_height="0.5dp"
                android:layout_marginLeft="4dp"
                android:layout_marginRight="4dp"
                android:background="@android:color/darker_gray"
                android:text="TextView" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/lyt_pw_groupmember_exit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/TextView02"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginLeft="12dp"
                android:layout_marginRight="12dp"
                android:gravity="left|center"
                android:text="exit"
                android:textSize="18sp" />

        </LinearLayout>

    </LinearLayout>
    

</RelativeLayout>

 

发表评论
用户名: 匿名